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
Copy file name to clipboardExpand all lines: README.md
+14-1Lines changed: 14 additions & 1 deletion
Original file line number
Diff line number
Diff line change
@@ -43,6 +43,7 @@ for a description of different tree storage algorithms.
43
43
## Table of Contents
44
44
45
45
-[Installation](#installation)
46
+
-[Warning](#warning)
46
47
-[Usage](#usage)
47
48
-[Accessing Data](#accessing-data)
48
49
-[Polymorphic hierarchies with STI](#polymorphic-hierarchies-with-sti)
@@ -60,19 +61,25 @@ Note that closure_tree only supports Rails 3.2 and later, and has test coverage
60
61
61
62
2. Run `bundle install`
62
63
63
-
3. Add `acts_as_tree` to your hierarchical model:
64
+
3. Add `acts_as_tree`or `has_closure_tree` (alias of the same method) to your hierarchical model:
64
65
65
66
```ruby
66
67
classTag < ActiveRecord::Base
67
68
acts_as_tree
68
69
end
70
+
71
+
classAnotherTag < ActiveRecord::Base
72
+
has_closure_tree
73
+
end
69
74
```
70
75
71
76
Make sure you check out the [large number options](#available-options) that `acts_as_tree` accepts.
72
77
73
78
Make sure you add `acts_as_tree`**after**`attr_accessible`and
74
79
`self.table_name =` lines in your model.
75
80
81
+
If you have other hierarchical gems in your stack, `acts_as_tree` method may not be safe to use. See the [Warning](#warning) section bellow.
82
+
76
83
4. Add a migration to add a `parent_id` column to the hierarchical model.
77
84
You may want to also [add a column for deterministic ordering of children](#sort_order), but that's optional.
78
85
@@ -101,6 +108,12 @@ Note that closure_tree only supports Rails 3.2 and later, and has test coverage
101
108
102
109
If you're starting from scratch you don't need to call `rebuild!`.
103
110
111
+
## Warning
112
+
113
+
The preferred method is `acts_as_tree`. However, other gems (like [ancestry](https://github.com/stefankroes/ancestry) or [acts_as_tree](https://github.com/amerine/acts_as_tree)) may use that method name too. If you have those gems as dependencies, use the alternative `has_closure_tree` method.
114
+
115
+
Bear in mind that using multiple hierarchy gems in the same model may not be safe. In fact, it's a safe bet to assume that it will cause all sorts of pain, suffering, and havoc. Avoid it.
0 commit comments