You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
[ancestry](https://github.com/stefankroes/ancestry) and
15
15
[acts_as_tree](https://github.com/amerine/acts_as_tree), and even more
16
16
awesome than [awesome_nested_set](https://github.com/collectiveidea/awesome_nested_set/),
@@ -25,16 +25,16 @@ closure_tree has some great features:
25
25
*__Best-in-class mutation performance__:
26
26
* 2 SQL INSERTs on node creation
27
27
* 3 SQL INSERT/UPDATEs on node reparenting
28
+
*__Support for [concurrency](#concurrency)__ (using [with_advisory_lock](https://github.com/mceachen/with_advisory_lock))
28
29
*__Support for Rails 3.2, 4.0, and 4.1__
29
-
*__Support for Ruby 1.9 and 2.1 (jRuby and Rubinius are still in development)__
30
+
*__Support for Ruby 1.9, 2.1, and jRuby 1.6.13
30
31
* Support for reparenting children (and all their descendants)
31
-
* Support for [concurrency](#concurrency) (using [with_advisory_lock](https://github.com/mceachen/with_advisory_lock))
32
-
* Support for polymorphism [STI](#sti) within the hierarchy
33
-
*```find_or_create_by_path``` for [building out hierarchies quickly and conveniently](#find_or_create_by_path)
34
-
* Support for [deterministic ordering](#deterministic-ordering) of children
32
+
* Support for [single-table inheritance (STI)](#sti) within the hierarchy
33
+
*```find_or_create_by_path``` for [building out heterogeneous hierarchies quickly and conveniently](#find_or_create_by_path)
34
+
* Support for [deterministic ordering](#deterministic-ordering)
35
35
* Support for [preordered](http://en.wikipedia.org/wiki/Tree_traversal#Pre-order) traversal of descendants
36
36
* Support for rendering trees in [DOT format](http://en.wikipedia.org/wiki/DOT_(graph_description_language)), using [Graphviz](http://www.graphviz.org/)
37
-
* Excellent [test coverage](#testing) in a variety of environments
37
+
* Excellent [test coverage](#testing) in a comprehensive variety of environments
38
38
39
39
See [Bill Karwin](http://karwin.blogspot.com/)'s excellent
40
40
[Models for hierarchical data presentation](http://www.slideshare.net/billkarwin/models-for-hierarchical-data)
@@ -153,30 +153,40 @@ child1.ancestry_path
153
153
154
154
### find_or_create_by_path
155
155
156
-
We can do all the node creation and add_child calls with one method call:
156
+
You can ```find``` as well as ```find_or_create``` by "ancestry paths".
157
+
158
+
If you provide an array of strings to these methods, they reference the `name` column in your
159
+
model, which can be overridden with the `:name_column` option provided to ```acts_as_tree```.
{type: 'EventLabel', name: 'Visit the Getty Center'}
183
+
])
172
184
```
173
-
This will pass the attribute hash of ```{:name => "home", :tag_type => "File"}``` to
174
-
```Tag.find_or_create_by_name``` if the root directory doesn't exist (and
175
-
```{:name => "chuck", :tag_type => "File"}```if the second-level tag doesn't exist, and so on).
176
185
177
186
### Moving nodes around the tree
178
187
179
-
Nodes can be moved around to other parents, and closure_tree moves the node's descendancy to the new parent foryou:
188
+
Nodes can be moved around to other parents, and closure_tree moves the node's descendancy to the
189
+
new parent for you:
180
190
181
191
```ruby
182
192
d = Tag.find_or_create_by_path %w(a b c d)
@@ -252,6 +262,7 @@ When you include ```acts_as_tree``` in your model, you can provide a hash to ove
252
262
*```:destroy``` will destroy all descendant nodes (which runs the destroy hooks on each child node)
253
263
*```:name_column``` used by #```find_or_create_by_path```, #```find_by_path```, and ```ancestry_path``` instance methods. This is primarily useful if the model only has one required field (like a "tag").
254
264
*```:order``` used to set up [deterministic ordering](#deterministic-ordering)
265
+
*```:touch``` delegates to the `belongs_to` annotation for the parent, so `touch`ing cascades to all children (the performance of this for deep trees isn't currently optimal).
255
266
256
267
## Accessing Data
257
268
@@ -529,7 +540,6 @@ end
529
540
530
541
```
531
542
532
-
533
543
## Testing
534
544
535
545
Closure tree is [tested under every valid combination](http://travis-ci.org/#!/mceachen/closure_tree) of
0 commit comments