Skip to content

Commit 8e690ae

Browse files
author
Fabien MICHEL
committed
Point out we can just set the parent on a child
1 parent 5ad0d58 commit 8e690ae

File tree

1 file changed

+8
-2
lines changed

1 file changed

+8
-2
lines changed

README.md

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -145,14 +145,20 @@ 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
155-
=> ["Grandparent", "Parent", "First Child"]
161+
=> ["Grandparent", "Parent", "First Child", "Fourth Child"]
156162
```
157163
158164
### find_or_create_by_path

0 commit comments

Comments
 (0)