From linicks at gmail.com Tue Mar 6 12:52:33 2007 From: linicks at gmail.com (Nick Pavlica) Date: Tue, 6 Mar 2007 10:52:33 -0700 Subject: [Betternestedset-talk] Counting Children Message-ID: Hi All, I decided to move to rails 1.2.2 and Better nested sets stable v50 or 0.1. Everything has been working as it should except this : <%= project.children_count %> Here is the error: undefined method `children_count' for # Thanks! --Nick From dontfall at gmail.com Tue Mar 6 14:30:53 2007 From: dontfall at gmail.com (Krishna Dole) Date: Tue, 6 Mar 2007 14:30:53 -0500 Subject: [Betternestedset-talk] Counting Children In-Reply-To: References: Message-ID: <8d64b97d0703061130w7a1b5b1foa5b333ee1ddc06b3@mail.gmail.com> Hi Nick, The short story is that I broke it and Fabien fixed it again in rev 51. However, children_count now returns the number of _direct_ children (as one would expect), while all_children_count returns the total number of nested children. I don't like breaking compatibility by changing methods like that, but the old children_count was misleading and inconsistent with acts_as_tree. k On 3/6/07, Nick Pavlica wrote: > Hi All, > I decided to move to rails 1.2.2 and Better nested sets stable v50 > or 0.1. Everything has been working as it should except this : > > <%= project.children_count %> > > > Here is the error: > > undefined method `children_count' for # > > Thanks! > --Nick > _______________________________________________ > Betternestedset-talk mailing list > Betternestedset-talk at rubyforge.org > http://rubyforge.org/mailman/listinfo/betternestedset-talk > From linicks at gmail.com Tue Mar 6 17:00:46 2007 From: linicks at gmail.com (Nick Pavlica) Date: Tue, 6 Mar 2007 15:00:46 -0700 Subject: [Betternestedset-talk] Counting Children In-Reply-To: <742E91B0-DCCA-4D97-80C1-7999A60CB9B4@loobmedia.com> References: <6774C84B-BE78-41D9-A993-C9F9C97D256C@loobmedia.com> <742E91B0-DCCA-4D97-80C1-7999A60CB9B4@loobmedia.com> Message-ID: Hi, I think I'm making some headway. Here is a quick synopsis: - Installed with: # ruby script/plugin install svn://rubyforge.org/var/svn/betternestedset/tags/stable/betternestedset ... files from svn .... # Exported revision 51 > $ grep "def children_count" lib/better_nested_set.rb > => def children_count(scope= {}) I did this grep and didn't find children_count. > Are you sure you're running r51 ? Decided to install using the trunk rather than stable: # ruby script/plugin install svn://rubyforge.org/var/svn/betternestedset/trunk ... files from svn .... # Exported revision 51 - I did the grep again and found children_count. > => def children_count(scope= {}) - I tested my code again, and everything seems to be working again. Many Thanks! -- Nick From linicks at gmail.com Tue Mar 6 17:39:42 2007 From: linicks at gmail.com (Nick Pavlica) Date: Tue, 6 Mar 2007 15:39:42 -0700 Subject: [Betternestedset-talk] Counting Children In-Reply-To: <8d64b97d0703061130w7a1b5b1foa5b333ee1ddc06b3@mail.gmail.com> References: <8d64b97d0703061130w7a1b5b1foa5b333ee1ddc06b3@mail.gmail.com> Message-ID: Hi Krishna, > However, children_count now returns the number of _direct_ > children (as one would expect), while all_children_count returns the > total number of nested children. Ironically, now that children_count is working I'm using all_children_count to get the behavior that I need. Thanks to everyone for all the help! -- Nick From mark.noten at itfc.be Wed Mar 7 05:12:28 2007 From: mark.noten at itfc.be (Mark.noten) Date: Wed, 7 Mar 2007 11:12:28 +0100 Subject: [Betternestedset-talk] Displaying a tree Message-ID: <487647a968270356edac6dc99bbfb22a@217.66.0.26> Hi all, some while ago there were some talks about putting some code on the Wiki that displays a tree. I see only this snippet about intending the left margin according to the level of a node. Displaying a tree You can use style="margin-left:<%= item.level %>em;" in your view to have items indented according to their level. Displaying vertical lines like in a mail thread is harder. Somebody in this list already pointed me out to use a view template for each node and recursively call display on each node. This would in fact display a tree or a subtree. Has anyone a small code example from displaying a tree? The helper methods are quite short and don't really cover this topic. Kind regards, Mark ________________________________________________ Message sent using UebiMiau 2.7.10 From mark.noten at itfc.be Sun Mar 18 07:10:21 2007 From: mark.noten at itfc.be (Mark Noten) Date: Sun, 18 Mar 2007 12:10:21 +0100 Subject: [Betternestedset-talk] Data migration problem Message-ID: <45FD1E1D.8090704@itfc.be> Hi all, I'm using better nested set (trunk revision 52) with Rails 1.2.2 and ruby 1.8.5 (2006-12-25 patchlevel 12) [x86_64-linux]. I'm having a problem with a data migration where the parent_id is always nil even when I set it for a child. I created a parent "ben_kunnen" and add a child "Noten Mark" to it with this migration: class AddAgentsData < ActiveRecord::Migration def self.up down dela = Product.find_or_create_by_name('DELA') level_1 = dela.levels.detect{ |l| l.code == '1' } level_3 = dela.levels.detect{ |l| l.code == '3' } ben_kunnen = Agent.create(:last_name => "Kunnen", :first_name => "Ben", :identification => "BKU", :product_id => dela.id, :parent_id => nil, :level_id => level_3.id) Agent.create(:last_name => "Noten", :first_name => "Mark", :identification => "MNO", :product_id => dela.id, :parent_id => ben_kunnen.id, :level_id => level_1.id) end def self.down Agent.delete_all end end mysql> select * from agents; +----+-----------+------------+----------------+------------+-----------+-----+-----+----------+ | id | last_name | first_name | identification | product_id | parent_id | lft | rgt | level_id | +----+-----------+------------+----------------+------------+-----------+-----+-----+----------+ | 1 | Kunnen | Ben | BKU | 1 | NULL | 1 | 2 | 4 | | 2 | Noten | Mark | MNO | 1 | NULL | 3 | 4 | 2 | +----+-----------+------------+----------------+------------+-----------+-----+-----+----------+ The parent_id column for the child "Noten Mark" remais always NULL in the database. The agent model is quite simple: class Agent < ActiveRecord::Base acts_as_nested_set :scope => :product_id belongs_to :level has_many :proposals validates_presence_of :last_name, :first_name, :identification, :product_id, :level_id validates_length_of :last_name, :first_name, :maximum => 30 validates_length_of :identification, :maximum => 10 validates_uniqueness_of :identification, :scope => :product_id # left out some methods that are not called in the migration end I tried the same statements in my Rails console and it gave me the same results: $>script/console Loading development environment. >> dela = Product.find_or_create_by_name('DELA') => #"/images/logo-dela.gif", "name"=>"DELA", "id"=>"1", "description"=>"DELA is de specialist in uitvaartverzekering en -verzorging met meer dan 70 jaar ervaring."}> >> level_1 = dela.levels.detect{ |l| l.code == '1' } => #"Verkoper", "code"=>"1", "product_id"=>"1", "id"=>"2", "description"=>nil, "commission_per_unit"=>"6.20"}> >> level_3 = dela.levels.detect{ |l| l.code == '3' } => #"Sectorchef", "code"=>"3", "product_id"=>"1", "id"=>"4", "description"=>nil, "commission_per_unit"=>"9.17"}> >> ben_kunnen = Agent.create(:last_name => "Kunnen", :first_name => "Ben", :identification => "BKU", :product_id => dela.id, :parent_id => nil, :level_id => level_3.id) => #4, "identification"=>"BKU", "lft"=>1, "product_id"=>1, "id"=>3, "first_name"=>"Ben", "rgt"=>2, "parent_id"=>nil, "last_name"=>"Kunnen"}, @errors=#>, @new_record_before_save=true> >> ben_kunnen.id => 3 >> Agent.create(:last_name => "Noten", :first_name => "Mark", :identification => "MNO", :product_id => dela.id, :parent_id => ben_kunnen.id, :level_id => level_1.id) => #2, "identification"=>"MNO", "lft"=>3, "product_id"=>1, "id"=>4, "first_name"=>"Mark", "rgt"=>4, "parent_id"=>nil, "last_name"=>"Noten"}, @errors=#>, @new_record_before_save=true> >> ben_kunnen.id => 3 You can see that the parent_id column of the child "Mark Noten" is nil. The strange thing is that when I execute above the statement ben_kunnen.id then it gives me the right id! So why can't I use the statement ben_kunnen.id set it set the right value for the child "Mark Noten"? Can anyone help me with this? Kind regards, Mark Noten Software engineer ITFC gcv E-mail: mark.noten at itfc.be GSM: +32 (484) 698 333 From dontfall at gmail.com Sun Mar 18 10:11:13 2007 From: dontfall at gmail.com (Krishna Dole) Date: Sun, 18 Mar 2007 09:11:13 -0500 Subject: [Betternestedset-talk] Data migration problem In-Reply-To: <45FD1E1D.8090704@itfc.be> References: <45FD1E1D.8090704@itfc.be> Message-ID: <8d64b97d0703180711r3cbd6e17k37476161f87f3aba@mail.gmail.com> Hi Mark, In the trunk version of better nested set, parent_id is a protected attribute.This prevents data corruption: if someone updated the parent_id without changing the lft/rgt values, queries using lft/rgt would produce incorrect results. So instead of n = Node.create(:parent_id => 3) # will be ignored you need to use the move_to methods n = Node.create n.move_to_child_of(3) # sets the parent and updates the lft/rgt values If for some reason you need to get around this, you can use Node.update_all, specifying the id of the record. If you are migrating a large amount of data, it may be faster to set the parent_ids with update_all, then when you have them loaded, run #renumber_all to set the lft/rgt values. Regards, Krishna On 3/18/07, Mark Noten wrote: > Hi all, > > I'm using better nested set (trunk revision 52) with Rails 1.2.2 and > ruby 1.8.5 (2006-12-25 patchlevel 12) [x86_64-linux]. I'm having a > problem with a data migration where the parent_id is always nil even > when I set it for a child. I created a parent "ben_kunnen" and add a > child "Noten Mark" to it with this migration: > > class AddAgentsData < ActiveRecord::Migration > def self.up > down > dela = Product.find_or_create_by_name('DELA') > level_1 = dela.levels.detect{ |l| l.code == '1' } > level_3 = dela.levels.detect{ |l| l.code == '3' } > ben_kunnen = Agent.create(:last_name => "Kunnen", :first_name => > "Ben", :identification => "BKU", :product_id => dela.id, :parent_id => > nil, :level_id => level_3.id) > Agent.create(:last_name => "Noten", :first_name => "Mark", > :identification => "MNO", :product_id => dela.id, :parent_id => > ben_kunnen.id, :level_id => level_1.id) > end > > def self.down > Agent.delete_all > end > end > > mysql> select * from agents; > +----+-----------+------------+----------------+------------+-----------+-----+-----+----------+ > | id | last_name | first_name | identification | product_id | parent_id > | lft | rgt | level_id | > +----+-----------+------------+----------------+------------+-----------+-----+-----+----------+ > | 1 | Kunnen | Ben | BKU | 1 | NULL > | 1 | 2 | 4 | > | 2 | Noten | Mark | MNO | 1 | NULL > | 3 | 4 | 2 | > +----+-----------+------------+----------------+------------+-----------+-----+-----+----------+ > > The parent_id column for the child "Noten Mark" remais always NULL in > the database. > > The agent model is quite simple: > > class Agent < ActiveRecord::Base > acts_as_nested_set :scope => :product_id > belongs_to :level > has_many :proposals > > validates_presence_of :last_name, :first_name, :identification, > :product_id, :level_id > validates_length_of :last_name, :first_name, :maximum => 30 > validates_length_of :identification, :maximum => 10 > validates_uniqueness_of :identification, :scope => :product_id > # left out some methods that are not called in the migration > end > > I tried the same statements in my Rails console and it gave me the same > results: > > $>script/console > Loading development environment. > >> dela = Product.find_or_create_by_name('DELA') > => # @attributes={"image_url"=>"/images/logo-dela.gif", "name"=>"DELA", > "id"=>"1", "description"=>"DELA is de specialist in uitvaartverzekering > en -verzorging met meer dan 70 jaar ervaring."}> > >> level_1 = dela.levels.detect{ |l| l.code == '1' } > => #"Verkoper", "code"=>"1", > "product_id"=>"1", "id"=>"2", "description"=>nil, > "commission_per_unit"=>"6.20"}> > >> level_3 = dela.levels.detect{ |l| l.code == '3' } > => #"Sectorchef", > "code"=>"3", "product_id"=>"1", "id"=>"4", "description"=>nil, > "commission_per_unit"=>"9.17"}> > >> ben_kunnen = Agent.create(:last_name => "Kunnen", :first_name => > "Ben", :identification => "BKU", :product_id => dela.id, :parent_id => > nil, :level_id => level_3.id) > => #4, > "identification"=>"BKU", "lft"=>1, "product_id"=>1, "id"=>3, > "first_name"=>"Ben", "rgt"=>2, "parent_id"=>nil, "last_name"=>"Kunnen"}, > @errors=# @base=#>, @new_record_before_save=true> > >> ben_kunnen.id > => 3 > >> Agent.create(:last_name => "Noten", :first_name => "Mark", > :identification => "MNO", :product_id => dela.id, :parent_id => > ben_kunnen.id, :level_id => level_1.id) > => #2, > "identification"=>"MNO", "lft"=>3, "product_id"=>1, "id"=>4, > "first_name"=>"Mark", "rgt"=>4, "parent_id"=>nil, "last_name"=>"Noten"}, > @errors=# @base=#>, @new_record_before_save=true> > >> ben_kunnen.id > => 3 > > You can see that the parent_id column of the child "Mark Noten" is nil. > The strange thing is that when I execute above the statement > ben_kunnen.id then it gives me the right id! So why can't I use the > statement ben_kunnen.id set it set the right value for the child "Mark > Noten"? > > Can anyone help me with this? > > Kind regards, > > 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 > From mark.noten at itfc.be Tue Mar 20 17:15:17 2007 From: mark.noten at itfc.be (Mark Noten) Date: Tue, 20 Mar 2007 22:15:17 +0100 Subject: [Betternestedset-talk] Question about selecting a parent Message-ID: <46004EE5.20606@itfc.be> Hi all, I'm using the collection_select helper method in the partial _form.rhtml that is used in the edit.rhtml. When I edit an agent I want to be able to select a manager or no manager at all. In use the additional :prompt option like this:


<%= collection_select("agent", "parent_id", @agents, :id, :full_name, {:prompt => "Select manager..."}, {:style => "width: 150px"}) %>

The @agents array comes from the edit action. Basically I retain all the current children of the agent and the agent itself because they can not be a manager: def edit @agent = Agent.find(params[:id]) @agents = Agent.find_all_ordered - @agent.full_set end The older Rails version always displayed the extra :prompt option. I use the following code after the save in my update action: def update @agent = Agent.find(params[:id]) if @agent.update_attributes(params[:agent]) @agent.move_to_child_of(params[:agent][:parent_id]) ... end If no manager was selected then the params[:agent][:parent_id] value is "". I can't use it as the parameter for the move_to_child_of method when the agent would have no manager. I tried to use the :include_blank => true option but that gave me an exception: Couldn't find Agent with ID= I think it is because the extra blank option is becomes also a parameter with as value the empty string "": *Parameters*: {"commit"=>"Edit", "id"=>"1", "agent"=>{"level_id"=>"4", "identification"=>"BKU", "product_id"=>"1", "first_name"=>"Ben", "last_name"=>"Kunnen", "parent_id"=>""}} The question is how do I select a manager (= the parent node) or none at all from a simple select box in my view and use the posted parent_id correctly in my actions? Kind regards, Mark Noten Software engineer ITFC gcv E-mail: mark.noten at itfc.be GSM: +32 (484) 698 333 From jc.michel at symetrie.com Tue Mar 20 18:20:06 2007 From: jc.michel at symetrie.com (Jean-Christophe Michel) Date: Tue, 20 Mar 2007 23:20:06 +0100 Subject: [Betternestedset-talk] Question about selecting a parent In-Reply-To: <46004EE5.20606@itfc.be> References: <46004EE5.20606@itfc.be> Message-ID: Hi, I see two possible solutions. Le 20 mars 07, ? 22:15, Mark Noten a ?crit : > I'm using the collection_select helper method in the partial > _form.rhtml > that is used in the edit.rhtml. When I edit an agent I want to be able > to select a manager or no manager at all. In use the additional :prompt > option like this: > >


> <%= collection_select("agent", "parent_id", @agents, :id, :full_name, > {:prompt => "Select manager..."}, {:style => "width: 150px"}) %>

You could use select instead of collection_select and add your prompt associated with root: <%= select('agent', 'parent_id', @agents.inject([[Agent.root.id, 'Select one...']]){|all, an_agent| [[an_agent.id, an_agent.full_name]]}) %> so your blank value would match the root of the tree and your node would be moved to be a level one child. (is it what you want ?) > The older Rails version always displayed the extra :prompt option. I > use > the following code after the save in my update action: > > def update > @agent = Agent.find(params[:id]) > if @agent.update_attributes(params[:agent]) > @agent.move_to_child_of(params[:agent][:parent_id]) > ... > end Second solution: test for empty parent_id here def update @agent = Agent.find(params[:id]) if @agent.update_attributes(params[:agent]) and !params[:agent][:parent_id].empty? @agent.move_to_child_of(params[:agent][:parent_id]) ;-) Jean-Christophe Michel -- symetrie.com Better Nested Set for rails: http://opensource.symetrie.com/trac/better_nested_set From mark.noten at itfc.be Wed Mar 21 06:50:07 2007 From: mark.noten at itfc.be (Mark.noten) Date: Wed, 21 Mar 2007 11:50:07 +0100 Subject: [Betternestedset-talk] Question about selecting a parent Message-ID: Hi Michel, thanks for your response. The code that I have now can be used to set a parent of an agent if the parent is not in the full_set of the agent. Otherwise it would be an impossible move. I just want to make an agent that has a parent now, make it a an agent with root level is 0. So actually it is about how to delete a parent from an agent and in fact making the agent a root node? If I know the answer to that question then I can probably put something together in my view to detach a parent from an agent. Kind regards, Mark --------- Original Message -------- From: betternestedset-talk at rubyforge.org To: betternestedset-talk at rubyforge.org Subject: Re: [Betternestedset-talk] Question about selecting a parent Date: 20/03/07 23:47 > Hi, > > I see two possible solutions. > > Le 20 mars 07, ? 22:15, Mark Noten a ?crit : > > I'm using the collection_select helper method in the partial > > _form.rhtml > > that is used in the edit.rhtml. When I edit an agent I want to be able > > to select a manager or no manager at all. In use the additional :prompt > > option like this: > > > > <p><label for="agent_parent_id">Manager</label><br/> > > <%= collection_select("agent", "parent_id", @agents, :id, :full_name, > > {:prompt => "Select manager..."}, {:style => "width: 150px"}) %></p> > > You could use select instead of collection_select and add your prompt > associated with root: > > <%= select('agent', 'parent_id', @agents.inject([[Agent.root.id, > 'Select one...']]){|all, an_agent| [[an_agent.id, > an_agent.full_name]]}) %> > > so your blank value would match the root of the tree and your node > would be moved to be a level one child. (is it what you want ?) > > > The older Rails version always displayed the extra :prompt option. I > > use > > the following code after the save in my update action: > > > > def update > > @agent = Agent.find(params[:id]) > > if @agent.update_attributes(params[:agent]) > > @agent.move_to_child_of(params[:agent][:parent_id]) > > ... > > end > > Second solution: test for empty parent_id here > > def update > @agent = Agent.find(params[:id]) > if @agent.update_attributes(params[:agent]) and > !params[:agent][:parent_id].empty? > @agent.move_to_child_of(params[:agent][:parent_id]) > > ;-) > > 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 > > ________________________________________________ Message sent using UebiMiau 2.7.10 From mark.noten at itfc.be Fri Mar 23 16:41:27 2007 From: mark.noten at itfc.be (Mark Noten) Date: Fri, 23 Mar 2007 21:41:27 +0100 Subject: [Betternestedset-talk] child node promoting to root node Message-ID: <46043B77.6040003@itfc.be> I don't understand something. Consider the following example: 1) parent = Node.create 2) child = Node.create child.move_to_child_of(parent) So the tree looks now like: parent (level=0) => this is the only root node | child (level=1) What instance method do I have to call on the child node to go to the following structure: parent (level=0) child (level=0) => now there are two root nodes So both nodes have become root nodes now. It may look like a strange situation that a child node would become a root node while it's old ancestors don't move inside the tree. I think it's a bit like The Godfather where one of the caporegimes could start their own family if they served well. It didn't happen in the movie though... ;-) Kind regards, Mark From dontfall at gmail.com Fri Mar 23 16:48:00 2007 From: dontfall at gmail.com (Krishna Dole) Date: Fri, 23 Mar 2007 16:48:00 -0400 Subject: [Betternestedset-talk] child node promoting to root node In-Reply-To: <46043B77.6040003@itfc.be> References: <46043B77.6040003@itfc.be> Message-ID: <8d64b97d0703231348s1af49444hc0880d128a2794e9@mail.gmail.com> move_to_root On 3/23/07, Mark Noten wrote: > I don't understand something. Consider the following example: > > 1) parent = Node.create > 2) child = Node.create > child.move_to_child_of(parent) > > So the tree looks now like: > > parent (level=0) => this is the only root node > | > child (level=1) > > What instance method do I have to call on the child node to go to the > following structure: > > parent (level=0) child (level=0) => now there are two root nodes > > So both nodes have become root nodes now. It may look like a strange > situation that a child node would become a root node while it's old > ancestors don't move inside the tree. I think it's a bit like The > Godfather where one of the caporegimes could start their own family if > they served well. It didn't happen in the movie though... ;-) > > Kind regards, > > Mark > _______________________________________________ > Betternestedset-talk mailing list > Betternestedset-talk at rubyforge.org > http://rubyforge.org/mailman/listinfo/betternestedset-talk > From mark.noten at itfc.be Mon Mar 26 13:59:53 2007 From: mark.noten at itfc.be (Mark Noten) Date: Mon, 26 Mar 2007 19:59:53 +0200 Subject: [Betternestedset-talk] child node promoting to root node In-Reply-To: <8d64b97d0703231348s1af49444hc0880d128a2794e9@mail.gmail.com> References: <46043B77.6040003@itfc.be> <8d64b97d0703231348s1af49444hc0880d128a2794e9@mail.gmail.com> Message-ID: <46080A19.9040106@itfc.be> Hi Krishna, I've reinstalled the betternestedset plugin from the latest development version in the /trunk directory. But I can't find the method move_to_root (not as an instance or class method) you're referring to. ./script/plugin install --force svn://rubyforge.org/var/svn/betternestedset/trunk A /home/mark/projects/ruby/mlm/trunk/vendor/plugins/betternestedset A /home/mark/projects/ruby/mlm/trunk/vendor/plugins/betternestedset/test ... A /home/mark/projects/ruby/mlm/trunk/vendor/plugins/betternestedset/README Exported revision 52. Thanks for your reply, Mark Krishna Dole wrote: > move_to_root > > On 3/23/07, Mark Noten wrote: > >> I don't understand something. Consider the following example: >> >> 1) parent = Node.create >> 2) child = Node.create >> child.move_to_child_of(parent) >> >> So the tree looks now like: >> >> parent (level=0) => this is the only root node >> | >> child (level=1) >> >> What instance method do I have to call on the child node to go to the >> following structure: >> >> parent (level=0) child (level=0) => now there are two root nodes >> >> So both nodes have become root nodes now. It may look like a strange >> situation that a child node would become a root node while it's old >> ancestors don't move inside the tree. I think it's a bit like The >> Godfather where one of the caporegimes could start their own family if >> they served well. It didn't happen in the movie though... ;-) >> >> Kind regards, >> >> Mark >> _______________________________________________ >> 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 > > > -- Met vriendelijke groet, Mark Noten Software engineer ITFC gcv E-mail: mark.noten at itfc.be GSM: +32 (484) 698 333 From dontfall at gmail.com Mon Mar 26 14:19:17 2007 From: dontfall at gmail.com (Krishna Dole) Date: Mon, 26 Mar 2007 14:19:17 -0400 Subject: [Betternestedset-talk] child node promoting to root node In-Reply-To: <46080A19.9040106@itfc.be> References: <46043B77.6040003@itfc.be> <8d64b97d0703231348s1af49444hc0880d128a2794e9@mail.gmail.com> <46080A19.9040106@itfc.be> Message-ID: <8d64b97d0703261119m61d09d3fkc6548151211c17a4@mail.gmail.com> Hi Mark, Sorry, I just discovered that method is only in the ez-set branch. Try move_to_left_of or move_to_right_of. Note that you cannot presently move nodes to different trees: you can promote a node to be a virtual root in the present tree, but not the root of a new tree. k On 3/26/07, Mark Noten wrote: > Hi Krishna, > > I've reinstalled the betternestedset plugin from the latest development > version in the /trunk directory. But I can't find the method > move_to_root (not as an instance or class method) you're referring to. > > ./script/plugin install --force > svn://rubyforge.org/var/svn/betternestedset/trunk > A /home/mark/projects/ruby/mlm/trunk/vendor/plugins/betternestedset > A /home/mark/projects/ruby/mlm/trunk/vendor/plugins/betternestedset/test > ... > A > /home/mark/projects/ruby/mlm/trunk/vendor/plugins/betternestedset/README > Exported revision 52. > > Thanks for your reply, > > Mark > > Krishna Dole wrote: > > move_to_root > > > > On 3/23/07, Mark Noten wrote: > > > >> I don't understand something. Consider the following example: > >> > >> 1) parent = Node.create > >> 2) child = Node.create > >> child.move_to_child_of(parent) > >> > >> So the tree looks now like: > >> > >> parent (level=0) => this is the only root node > >> | > >> child (level=1) > >> > >> What instance method do I have to call on the child node to go to the > >> following structure: > >> > >> parent (level=0) child (level=0) => now there are two root nodes > >> > >> So both nodes have become root nodes now. It may look like a strange > >> situation that a child node would become a root node while it's old > >> ancestors don't move inside the tree. I think it's a bit like The > >> Godfather where one of the caporegimes could start their own family if > >> they served well. It didn't happen in the movie though... ;-) > >> > >> Kind regards, > >> > >> Mark > >> _______________________________________________ > >> 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 > > > > > > > > > -- > 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 > From lindsaye at gmail.com Wed Mar 28 23:00:37 2007 From: lindsaye at gmail.com (Lindsay Evans) Date: Thu, 29 Mar 2007 13:00:37 +1000 Subject: [Betternestedset-talk] MySQL optimisation in move_to Message-ID: Hello, Just noticed that move_to_child_of was running pretty slow (around 20 seconds) on a table with about 2.2 million rows, but was only updating about 13000 records. I've looked at the SQL move_to produces, and it seems to be doing a full table scan in it's update, so I made this change to limit it to only the rows that would be updated (sorry for no patch, my copy of better_nested_set.rb is pretty messy at the moment from debugging): update_scope_condition = " AND ((#{left_col_name} BETWEEN #{a} AND #{b}) OR (#{left_col_name} BETWEEN #{c} AND #{d}) OR (#{self.class.primary_key} = #{self.id}))" base_set_class.update_all([existing SQL], new_scope_condition + update_scope_condition) The query now runs in under 1 second, and seems to produce the same result. I'll do some more testing & provide a patch if there is interest. -- Lindsay Evans http://linz.id.au/ From lindsaye at gmail.com Wed Mar 28 23:21:54 2007 From: lindsaye at gmail.com (Lindsay Evans) Date: Thu, 29 Mar 2007 13:21:54 +1000 Subject: [Betternestedset-talk] MySQL optimisation in move_to In-Reply-To: References: Message-ID: oops, that second line should read: base_set_class.update_all([existing SQL], scope_condition + update_scope_condition I need more coffee :p -- Lindsay Evans http://lindsayevans.com/