Stephen Schor
2008-Jan-30 22:44 UTC
[Betternestedset-talk] move_to_child_of() on existing records.
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
Krishna Dole
2008-Jan-31 01:49 UTC
[Betternestedset-talk] move_to_child_of() on existing records.
Hi Stephen, Currently the API does not support moving nodes between trees. You may want to make sure you are using the trunk version of the code since I vaguely recall putting a check in there that would raise if you tried to move nodes between trees. Or maybe I just imagined it. Krishna On Jan 30, 2008 2:44 PM, Stephen Schor <beholdthepanda at gmail.com> wrote:> 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 > > _______________________________________________ > Betternestedset-talk mailing list > Betternestedset-talk at rubyforge.org > http://rubyforge.org/mailman/listinfo/betternestedset-talk > >
Stephen Schor
2008-Jan-31 03:23 UTC
[Betternestedset-talk] move_to_child_of() on existing records.
Hi Krishna, Thanks so much for the quick response - I really appreciate it. I''ll take double check that I''ve got the latest and greatest. (I may be using a version from /tags/stable). -Stephen On Jan 30, 2008 8:49 PM, Krishna Dole <dontfall at gmail.com> wrote:> Hi Stephen, > > Currently the API does not support moving nodes between trees. > > You may want to make sure you are using the trunk version of the code > since I vaguely recall putting a check in there that would raise if > you tried to move nodes between trees. Or maybe I just imagined it. > > Krishna > > On Jan 30, 2008 2:44 PM, Stephen Schor <beholdthepanda at gmail.com> wrote: > > 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 > > > > _______________________________________________ > > Betternestedset-talk mailing list > > Betternestedset-talk at rubyforge.org > > http://rubyforge.org/mailman/listinfo/betternestedset-talk > > > > > _______________________________________________ > Betternestedset-talk mailing list > Betternestedset-talk at rubyforge.org > http://rubyforge.org/mailman/listinfo/betternestedset-talk >-------------- next part -------------- An HTML attachment was scrubbed... URL: http://rubyforge.org/pipermail/betternestedset-talk/attachments/20080130/793d76cc/attachment.html