[Betternestedset-talk] move_to_child_of() on existing records.

Stephen Schor beholdthepanda at gmail.com
Wed Jan 30 17:44:51 EST 2008


Hey all,

I have a quick question about some weirdo behavior I'm seeing in my tables.
I have a table that looks like:

ID     NAME     LFT     RGT     PARENT_ID     TREE_ID
18     dogs        1         2          null                  18
19     cats         1         4          null                  19
20     smalldogs 2        3          19                    19

and say to myself 'oops' - smalldogs is really a child of 'dogs.' - not cats
opening up a script/console session I play around with the records...

>> t = Team.find(20)
=> #<Team id: 20, name: "Small Dogs", lft: 2, rgt: 3, parent_id: 19,
tree_id: 19>
>> t.tree_id = 18
=> 18
>> t.save
=> true
>> t.move_to_child_of(Team.find(18))
=> nil

My table ends up looking like
ID     NAME     LFT     RGT     PARENT_ID     TREE_ID
18     dogs        1         2          null                  18
19     cats         1         4          null                  19
20     smalldogs 2        3          19                    18

So it's a little weird that smalldog.parent_id and dogs.lft/rgt weren't
adjusted after calling move_to_child_of.
So - is there a common pattern for moving existing nodes into other trees
when using the scope option?

Thanks!
-Stephen
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://rubyforge.org/pipermail/betternestedset-talk/attachments/20080130/3cab7014/attachment.html 


More information about the Betternestedset-talk mailing list