I''ve got a tree with virtual roots scoped on a foreign_id key. This works. However, if I try to move a root to the child of another node, I get the following error (pasted below). Is this correct behaviour? Does this mean once you create a node, it can not move into another tree? If this is the case... does that mean the only way to move a node into another tree is to delete and re-create it? Thanks Mikel Error follows: ?> p1 => #<Paragraph:0x3565150 @attributes={"text"=>nil, "section_id"=>"1", "lft"=>"1", "id"=>"1", "parent_id"=>nil, "rgt"=>"2"}>>> p2=> #<Paragraph:0x3553b30 @attributes={"text"=>nil, "section_id"=>"2", "lft"=>"1", "id"=>"2", "parent_id"=>nil, "rgt"=>"2"}>>> p2.move_to_child_of(p1.id)ActiveRecord::ActiveRecordError: Impossible move, target node cannot be inside moved tree. from ./script/../config/../config/../vendor/plugins/betternestedset/lib/better_nested_set.rb:933:in `move_to'' from ./script/../config/../config/../vendor/plugins/betternestedset/lib/better_nested_set.rb:1109:in `with_optional_transaction'' from /usr/local/lib/ruby/gems/1.8/gems/activerecord-1.15.3/lib/active_record/connection_adapters/abstract/database_statements.rb:59:in `transaction'' from /usr/local/lib/ruby/gems/1.8/gems/activerecord-1.15.3/lib/active_record/transactions.rb:95:in `transaction'' from /usr/local/lib/ruby/gems/1.8/gems/activerecord-1.15.3/lib/active_record/transactions.rb:121:in `transaction'' from ./script/../config/../config/../vendor/plugins/betternestedset/lib/better_nested_set.rb:1109:in `with_optional_transaction'' from ./script/../config/../config/../vendor/plugins/betternestedset/lib/better_nested_set.rb:924:in `move_to'' from ./script/../config/../config/../vendor/plugins/betternestedset/lib/better_nested_set.rb:865:in `move_to_child_of'' from (irb):68>>
Hi, Le 5 juil. 07 ? 11:09, Mikel Lindsaar a ?crit :> However, if I try to move a root to the child of another node, I get > the following error (pasted below). > > Is this correct behaviour? Does this mean once you create a node, it > can not move into another tree? > > If this is the case... does that mean the only way to move a node into > another tree is to delete and re-create it?Seems that scope is ignored when preventing move of nodes ;-) Jean-Christophe Michel -- symetrie.com Better Nested Set for rails: http://opensource.symetrie.com/trac/better_nested_set
yes and yes. currently nodes cannot be moved between trees (though this behavior could be added). the (admittedly klunky) workaround is to delete the node from one tree and create it in another. krishna On 7/5/07, Mikel Lindsaar <raasdnil at gmail.com> wrote:> I''ve got a tree with virtual roots scoped on a foreign_id key. > > This works. > > However, if I try to move a root to the child of another node, I get > the following error (pasted below). > > Is this correct behaviour? Does this mean once you create a node, it > can not move into another tree? > > If this is the case... does that mean the only way to move a node into > another tree is to delete and re-create it? > > Thanks > > Mikel > > Error follows: > > ?> p1 > => #<Paragraph:0x3565150 @attributes={"text"=>nil, "section_id"=>"1", > "lft"=>"1", "id"=>"1", "parent_id"=>nil, "rgt"=>"2"}> > >> p2 > => #<Paragraph:0x3553b30 @attributes={"text"=>nil, "section_id"=>"2", > "lft"=>"1", "id"=>"2", "parent_id"=>nil, "rgt"=>"2"}> > >> p2.move_to_child_of(p1.id) > ActiveRecord::ActiveRecordError: Impossible move, target node cannot > be inside moved tree. > from ./script/../config/../config/../vendor/plugins/betternestedset/lib/better_nested_set.rb:933:in > `move_to'' > from ./script/../config/../config/../vendor/plugins/betternestedset/lib/better_nested_set.rb:1109:in > `with_optional_transaction'' > from /usr/local/lib/ruby/gems/1.8/gems/activerecord-1.15.3/lib/active_record/connection_adapters/abstract/database_statements.rb:59:in > `transaction'' > from /usr/local/lib/ruby/gems/1.8/gems/activerecord-1.15.3/lib/active_record/transactions.rb:95:in > `transaction'' > from /usr/local/lib/ruby/gems/1.8/gems/activerecord-1.15.3/lib/active_record/transactions.rb:121:in > `transaction'' > from ./script/../config/../config/../vendor/plugins/betternestedset/lib/better_nested_set.rb:1109:in > `with_optional_transaction'' > from ./script/../config/../config/../vendor/plugins/betternestedset/lib/better_nested_set.rb:924:in > `move_to'' > from ./script/../config/../config/../vendor/plugins/betternestedset/lib/better_nested_set.rb:865:in > `move_to_child_of'' > from (irb):68 > >> > _______________________________________________ > Betternestedset-talk mailing list > Betternestedset-talk at rubyforge.org > http://rubyforge.org/mailman/listinfo/betternestedset-talk >
Hey all, This behavior was fixed in my code by a combination of the patch I emailed out a while ago and a very simple conditional check. If you move a node up to be its parent''s peer, you can then make the former parent a subordinate value of its subtree. That is the case in which you generally get the error below. I have code that actually allows you to directly set a parent to be a child of one of its children...this code promotes all of the parent''s children to be its peers, and then moves the parent node into the target subtree. It works very well, no errors, etc. I''d be happy to demonstrate, but I''ve got places to be today. Perhaps tomorrow evening, if this is of interest? -Jon -----Original Message----- From: betternestedset-talk-bounces at rubyforge.org [mailto:betternestedset-talk-bounces at rubyforge.org] On Behalf Of Jean-Christophe Michel Sent: Thursday, July 05, 2007 7:32 AM To: betternestedset-talk at rubyforge.org Subject: Re: [Betternestedset-talk] Virtual roots Hi, Le 5 juil. 07 ? 11:09, Mikel Lindsaar a ?crit :> However, if I try to move a root to the child of another node, I get > the following error (pasted below). > > Is this correct behaviour? Does this mean once you create a node, it > can not move into another tree? > > If this is the case... does that mean the only way to move a node into > another tree is to delete and re-create it?Seems that scope is ignored when preventing move of nodes ;-) Jean-Christophe Michel -- symetrie.com Better Nested Set for rails: http://opensource.symetrie.com/trac/better_nested_set _______________________________________________ Betternestedset-talk mailing list Betternestedset-talk at rubyforge.org http://rubyforge.org/mailman/listinfo/betternestedset-talk
Wow, thanks for all you fast replies! Great list :) Jon, that would be great :) Maybe we could wrap it up better and add it into better nested set? Regards Mikel On 7/5/07, Jonathan Mischo <jmischo at quagility.com> wrote:> Hey all, > > This behavior was fixed in my code by a combination of the patch I emailed > out a while ago and a very simple conditional check. If you move a node up > to be its parent''s peer, you can then make the former parent a subordinate > value of its subtree. That is the case in which you generally get the error > below. I have code that actually allows you to directly set a parent to be > a child of one of its children...this code promotes all of the parent''s > children to be its peers, and then moves the parent node into the target > subtree. It works very well, no errors, etc. > > I''d be happy to demonstrate, but I''ve got places to be today. Perhaps > tomorrow evening, if this is of interest? > > -Jon > > -----Original Message----- > From: betternestedset-talk-bounces at rubyforge.org > [mailto:betternestedset-talk-bounces at rubyforge.org] On Behalf Of > Jean-Christophe Michel > Sent: Thursday, July 05, 2007 7:32 AM > To: betternestedset-talk at rubyforge.org > Subject: Re: [Betternestedset-talk] Virtual roots > > Hi, > > > Le 5 juil. 07 ? 11:09, Mikel Lindsaar a ?crit : > > However, if I try to move a root to the child of another node, I get > > the following error (pasted below). > > > > Is this correct behaviour? Does this mean once you create a node, it > > can not move into another tree? > > > > If this is the case... does that mean the only way to move a node into > > another tree is to delete and re-create it? > > Seems that scope is ignored when preventing move of nodes ;-) > > Jean-Christophe Michel > -- > symetrie.com > > Better Nested Set for rails: > http://opensource.symetrie.com/trac/better_nested_set > > > _______________________________________________ > 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 >
I''m not a committer, so I don''t think I can. The code I modified mainly just simplified some of the code to make it work in a way that I felt was more sensible. On further reflection, though, I believe that it doesn''t QUITE fix the scoping issue...more that it just defaults sensibly. I need to review my code a bit more, but I did send the patch to the list. I''ll definitely send some examples of how to work with this aspect, though, and perhaps work on recoding some of the scoping stuff when I have a little time (which won''t be for at least a week or two). -Jon -----Original Message----- From: betternestedset-talk-bounces at rubyforge.org [mailto:betternestedset-talk-bounces at rubyforge.org] On Behalf Of Mikel Lindsaar Sent: Thursday, July 05, 2007 5:42 PM To: betternestedset-talk at rubyforge.org Subject: Re: [Betternestedset-talk] Virtual roots Wow, thanks for all you fast replies! Great list :) Jon, that would be great :) Maybe we could wrap it up better and add it into better nested set? Regards Mikel On 7/5/07, Jonathan Mischo <jmischo at quagility.com> wrote:> Hey all, > > This behavior was fixed in my code by a combination of the patch I emailed > out a while ago and a very simple conditional check. If you move a nodeup> to be its parent''s peer, you can then make the former parent a subordinate > value of its subtree. That is the case in which you generally get theerror> below. I have code that actually allows you to directly set a parent tobe> a child of one of its children...this code promotes all of the parent''s > children to be its peers, and then moves the parent node into the target > subtree. It works very well, no errors, etc. > > I''d be happy to demonstrate, but I''ve got places to be today. Perhaps > tomorrow evening, if this is of interest? > > -Jon > > -----Original Message----- > From: betternestedset-talk-bounces at rubyforge.org > [mailto:betternestedset-talk-bounces at rubyforge.org] On Behalf Of > Jean-Christophe Michel > Sent: Thursday, July 05, 2007 7:32 AM > To: betternestedset-talk at rubyforge.org > Subject: Re: [Betternestedset-talk] Virtual roots > > Hi, > > > Le 5 juil. 07 ? 11:09, Mikel Lindsaar a ?crit : > > However, if I try to move a root to the child of another node, I get > > the following error (pasted below). > > > > Is this correct behaviour? Does this mean once you create a node, it > > can not move into another tree? > > > > If this is the case... does that mean the only way to move a node into > > another tree is to delete and re-create it? > > Seems that scope is ignored when preventing move of nodes ;-) > > Jean-Christophe Michel > -- > symetrie.com > > Better Nested Set for rails: > http://opensource.symetrie.com/trac/better_nested_set > > > _______________________________________________ > 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 >_______________________________________________ Betternestedset-talk mailing list Betternestedset-talk at rubyforge.org http://rubyforge.org/mailman/listinfo/betternestedset-talk