Skip to content

Commit a840e60

Browse files
committed
Merge pull request #177 from fabien-michel/patch-1
Point out we can just set the parent on a child
2 parents 5e69112 + 023608c commit a840e60

File tree

1 file changed

+7
-1
lines changed

1 file changed

+7
-1
lines changed

README.md

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -145,11 +145,17 @@ child3 = Tag.new(name: 'Third Child')
145145
parent.add_child child3
146146
```
147147
148+
Or by setting the parent on the child :
149+
150+
```ruby
151+
Tag.create(name: 'Fourth Child', parent: parent)
152+
```
153+
148154
Then:
149155
150156
```ruby
151157
grandparent.self_and_descendants.collect(&:name)
152-
=> ["Grandparent", "Parent", "First Child", "Second Child", "Third Child"]
158+
=> ["Grandparent", "Parent", "First Child", "Second Child", "Third Child", "Fourth Child"]
153159
154160
child1.ancestry_path
155161
=> ["Grandparent", "Parent", "First Child"]

0 commit comments

Comments
 (0)