Mark.noten
2007-Apr-02 12:12 UTC
[Betternestedset-talk] getting :scope => :root_id to work
Hey Sam, the thing is that for me the products are already defined up front before creating a node (a sales person). A product is just a "simple" Rails generated model that doesn''t depend on the nested set API. When an administrator creates a new sales person, he or she first selects the product(_id) from a select box and then a manager (a sales person too) for this sales agent (if any). The model of my sales person just has a :belongs_to :product and a betternestedset :scope => product_id. So I actually don''t need any callbacks. Kind regards, Mark --------- Original Message -------- From: betternestedset-talk at rubyforge.org To: betternestedset-talk at rubyforge.org <betternestedset-talk at rubyforge.org> Subject: Re: [Betternestedset-talk] getting :scope => :root_id to work Date: 02/04/07 02:32> 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 theexpected> > behavior of the scope parameter. The scope column will not be filledin> > by the better nested set API. You should use it to make differenttrees> > 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 effecton> > > 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 remainsblank.> > > If this is on purpose and there are no performance issues theI''ll go> > > with this. If there is a way to make it work, pleaseillustrate.> > > > > > 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/ > _______________________________________________ > Betternestedset-talk mailing list > Betternestedset-talk at rubyforge.org > http://rubyforge.org/mailman/listinfo/betternestedset-talk > >________________________________________________ Message sent using UebiMiau 2.7.10