First of all thanks for the hard work. I''m trying to get scope to work as follows: class Topic < ActiveRecord::Base acts_as_nested_set :scope => :root_id Unfortunately, making a topic the child of another has no effect on the root_id value. Am I doing something wrong?>> t = Topic.create=> #<Topic:0x310fbf0 @attributes={"title"=>nil, "lft"=>1, "id"=>11, "root_id"=>nil, "content"=>nil, "user_id"=>nil, "rgt"=>2, "parent_id"=>nil}, @new_record_before_save=true, @new_record=false, @errors=#<ActiveRecord::Errors:0x310f204 @base=#<Topic:0x310fbf0 ...>, @errors={}>>>> tt = Topic.create=> #<Topic:0x3105d80 @attributes={"title"=>nil, "lft"=>3, "id"=>12, "root_id"=>nil, "content"=>nil, "user_id"=>nil, "rgt"=>4, "parent_id"=>nil}, @new_record_before_save=true, @new_record=false, @errors=#<ActiveRecord::Errors:0x31055c4 @base=#<Topic:0x3105d80 ...>, @errors={}>>>> t.root=> #<Topic:0x30fed8c @attributes={"title"=>nil, "lft"=>"1", "id"=>"11", "root_id"=>nil, "content"=>nil, "user_id"=>nil, "rgt"=>"2", "parent_id"=>nil}>>> tt.move_to_child_of(t)=> #<Topic:0x310fbf0 @communities=nil, @attributes={"title"=>nil, "lft"=>"1", "id"=>"11", "root_id"=>nil, "content"=>nil, "user_id"=>nil, "rgt"=>"4", "parent_id"=>nil}, @starters=nil, @user=nil, @new_record_before_save=true, @new_record=false, @topic_starters=nil, @errors=#<ActiveRecord::Errors:0x310f204 @base=#<Topic:0x310fbf0 ...>, @errors={}>>>> tt=> #<Topic:0x3105d80 @communities=nil, @attributes={"title"=>nil, "lft"=>"2", "id"=>"12", "root_id"=>nil, "content"=>nil, "user_id"=>nil, "rgt"=>"3", "parent_id"=>"11"}, @starters=nil, @user=nil, @new_record_before_save=true, @new_record=false, @topic_starters=nil, @errors=#<ActiveRecord::Errors:0x31055c4 @base=#<Topic:0x3105d80 ...>, @errors={}>> As you can see the parent_id is set properly but root remains blank. If this is on purpose and there are no performance issues the I''ll go with this. If there is a way to make it work, please illustrate. Sam
Mark Noten
2007-Apr-01 16:45 UTC
[Betternestedset-talk] getting :scope => :root_id to work
Hey Sam, I don''t think you''re doing some wrong. You''re just getting the expected behavior of the scope parameter. The scope column will not be filled in by the better nested set API. You should use it to make different trees for an already existing classification. Here''s an example how I use it. There are different products for sale and you want to make a group of sales persons (better nested set) for each product, you can say the :scope => :product_id. Kind regards, Mark SB wrote:> First of all thanks for the hard work. > > I''m trying to get scope to work as follows: > > class Topic < ActiveRecord::Base > acts_as_nested_set :scope => :root_id > > > > Unfortunately, making a topic the child of another has no effect on > the root_id value. Am I doing something wrong? > > > >>> t = Topic.create >>> > => #<Topic:0x310fbf0 @attributes={"title"=>nil, "lft"=>1, "id"=>11, > "root_id"=>nil, "content"=>nil, "user_id"=>nil, "rgt"=>2, > "parent_id"=>nil}, @new_record_before_save=true, @new_record=false, > @errors=#<ActiveRecord::Errors:0x310f204 @base=#<Topic:0x310fbf0 ...>, > @errors={}>> > >>> tt = Topic.create >>> > => #<Topic:0x3105d80 @attributes={"title"=>nil, "lft"=>3, "id"=>12, > "root_id"=>nil, "content"=>nil, "user_id"=>nil, "rgt"=>4, > "parent_id"=>nil}, @new_record_before_save=true, @new_record=false, > @errors=#<ActiveRecord::Errors:0x31055c4 @base=#<Topic:0x3105d80 ...>, > @errors={}>> > >>> t.root >>> > => #<Topic:0x30fed8c @attributes={"title"=>nil, "lft"=>"1", > "id"=>"11", "root_id"=>nil, "content"=>nil, "user_id"=>nil, > "rgt"=>"2", "parent_id"=>nil}> > >>> tt.move_to_child_of(t) >>> > => #<Topic:0x310fbf0 @communities=nil, @attributes={"title"=>nil, > "lft"=>"1", "id"=>"11", "root_id"=>nil, "content"=>nil, > "user_id"=>nil, "rgt"=>"4", "parent_id"=>nil}, @starters=nil, > @user=nil, @new_record_before_save=true, @new_record=false, > @topic_starters=nil, @errors=#<ActiveRecord::Errors:0x310f204 > @base=#<Topic:0x310fbf0 ...>, @errors={}>> > >>> tt >>> > => #<Topic:0x3105d80 @communities=nil, @attributes={"title"=>nil, > "lft"=>"2", "id"=>"12", "root_id"=>nil, "content"=>nil, > "user_id"=>nil, "rgt"=>"3", "parent_id"=>"11"}, @starters=nil, > @user=nil, @new_record_before_save=true, @new_record=false, > @topic_starters=nil, @errors=#<ActiveRecord::Errors:0x31055c4 > @base=#<Topic:0x3105d80 ...>, @errors={}>> > > As you can see the parent_id is set properly but root remains blank. > If this is on purpose and there are no performance issues the I''ll go > with this. If there is a way to make it work, please illustrate. > > Sam > _______________________________________________ > Betternestedset-talk mailing list > Betternestedset-talk at rubyforge.org > http://rubyforge.org/mailman/listinfo/betternestedset-talk > > >-- Met vriendelijke groet, Mark Noten Software engineer ITFC gcv E-mail: mark.noten at itfc.be GSM: +32 (484) 698 333
Mark, Thanks for the reply, after digging through the archives some more I found out that you''re supposed to define it yourself with a callback or whatever. Still getting acquainted with the plugin but I guess the major benefit is to be able to Product.find(:all, :root_id => 3) and then put that into an array. I''d love to see a concrete example of how it''s actually being used with some code snippets. sam On 4/2/07, Mark Noten <mark.noten at itfc.be> wrote:> Hey Sam, > > I don''t think you''re doing some wrong. You''re just getting the expected > behavior of the scope parameter. The scope column will not be filled in > by the better nested set API. You should use it to make different trees > for an already existing classification. > > Here''s an example how I use it. There are different products for sale > and you want to make a group of sales persons (better nested set) for > each product, you can say the :scope => :product_id. > > Kind regards, > > Mark > > SB wrote: > > First of all thanks for the hard work. > > > > I''m trying to get scope to work as follows: > > > > class Topic < ActiveRecord::Base > > acts_as_nested_set :scope => :root_id > > > > > > > > Unfortunately, making a topic the child of another has no effect on > > the root_id value. Am I doing something wrong? > > > > > > > >>> t = Topic.create > >>> > > => #<Topic:0x310fbf0 @attributes={"title"=>nil, "lft"=>1, "id"=>11, > > "root_id"=>nil, "content"=>nil, "user_id"=>nil, "rgt"=>2, > > "parent_id"=>nil}, @new_record_before_save=true, @new_record=false, > > @errors=#<ActiveRecord::Errors:0x310f204 @base=#<Topic:0x310fbf0 ...>, > > @errors={}>> > > > >>> tt = Topic.create > >>> > > => #<Topic:0x3105d80 @attributes={"title"=>nil, "lft"=>3, "id"=>12, > > "root_id"=>nil, "content"=>nil, "user_id"=>nil, "rgt"=>4, > > "parent_id"=>nil}, @new_record_before_save=true, @new_record=false, > > @errors=#<ActiveRecord::Errors:0x31055c4 @base=#<Topic:0x3105d80 ...>, > > @errors={}>> > > > >>> t.root > >>> > > => #<Topic:0x30fed8c @attributes={"title"=>nil, "lft"=>"1", > > "id"=>"11", "root_id"=>nil, "content"=>nil, "user_id"=>nil, > > "rgt"=>"2", "parent_id"=>nil}> > > > >>> tt.move_to_child_of(t) > >>> > > => #<Topic:0x310fbf0 @communities=nil, @attributes={"title"=>nil, > > "lft"=>"1", "id"=>"11", "root_id"=>nil, "content"=>nil, > > "user_id"=>nil, "rgt"=>"4", "parent_id"=>nil}, @starters=nil, > > @user=nil, @new_record_before_save=true, @new_record=false, > > @topic_starters=nil, @errors=#<ActiveRecord::Errors:0x310f204 > > @base=#<Topic:0x310fbf0 ...>, @errors={}>> > > > >>> tt > >>> > > => #<Topic:0x3105d80 @communities=nil, @attributes={"title"=>nil, > > "lft"=>"2", "id"=>"12", "root_id"=>nil, "content"=>nil, > > "user_id"=>nil, "rgt"=>"3", "parent_id"=>"11"}, @starters=nil, > > @user=nil, @new_record_before_save=true, @new_record=false, > > @topic_starters=nil, @errors=#<ActiveRecord::Errors:0x31055c4 > > @base=#<Topic:0x3105d80 ...>, @errors={}>> > > > > As you can see the parent_id is set properly but root remains blank. > > If this is on purpose and there are no performance issues the I''ll go > > with this. If there is a way to make it work, please illustrate. > > > > Sam > > _______________________________________________ > > Betternestedset-talk mailing list > > Betternestedset-talk at rubyforge.org > > http://rubyforge.org/mailman/listinfo/betternestedset-talk > > > > > > > > > -- > Met vriendelijke groet, > > Mark Noten > Software engineer > ITFC gcv > E-mail: mark.noten at itfc.be > GSM: +32 (484) 698 333 > > _______________________________________________ > Betternestedset-talk mailing list > Betternestedset-talk at rubyforge.org > http://rubyforge.org/mailman/listinfo/betternestedset-talk >-- http://baron.vc/