Hello, I have a tree structure that needs to be converted into a nested set. A great deal of work has already been done on the tree items, so maintaining the integrity of the id''s is mandatory. However I need the ability to access entire branches of the tree, which is what Nested set does. Does anyone have any suggestions on how to efficiently transfer the tree to the nested set and create the left and right boundaries? Thanks! --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---
Awesome_Nested_Set looks interesting as well. Maybe I should use that? On Feb 17, 11:39 am, Mindtonic <mindto...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote:> Hello, > > I have a tree structure that needs to be converted into a nested set. > A great deal of work has already been done on the tree items, so > maintaining the integrity of the id''s is mandatory. However I need > the ability to access entire branches of the tree, which is what > Nested set does. Does anyone have any suggestions on how to > efficiently transfer the tree to the nested set and create the left > and right boundaries? > > Thanks!--~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe@googlegroups.com For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---
anyone have any ideas? On Feb 17, 1:33 pm, Mindtonic <mindto...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote:> Awesome_Nested_Set looks interesting as well. Maybe I should use > that? > > On Feb 17, 11:39 am, Mindtonic <mindto...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote: > > > Hello, > > > I have a tree structure that needs to be converted into a nested set. > > A great deal of work has already been done on the tree items, so > > maintaining the integrity of the id''s is mandatory. However I need > > the ability to access entire branches of the tree, which is what > > Nested set does. Does anyone have any suggestions on how to > > efficiently transfer the tree to the nested set and create the left > > and right boundaries? > > > Thanks!--~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe@googlegroups.com For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---
Roderick van Domburg
2009-Feb-18 16:45 UTC
Re: Converting Acts_As_Tree to Acts_As_Nested_Set
Mindtonic wrote:> anyone have any ideas?You should definitely use awesome_nested_set instead of acts_as_nested_set. The former has much cleaner code. If the size of your tree allows it, I would choose to recreate it using awesome_nested_set using move_to instead of figuring out a smart algorithm for conversion. It''ll spare you development time and guarantee a proper conversion. -- Roderick van Domburg http://www.nedforce.com -- Posted via http://www.ruby-forum.com/. --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---
Is awesome_nested_set a better choice than better_nested_set? I found the following on the better_nested_set wiki page: Migrating from acts_as_tree In reference to migrating from acts_as_tree Krishna Dole said, “If you have multiple trees in your table, it is a little more complicated. You first need to give each tree scope (add a tree_id column) and then run the above method on a member of each tree.” Not completely understanding that statement, I set out to implement it in a migration. Here is my result which appears to work. In this example, I am using a model named Categories: class ConvertCategoriesToNestedSet < ActiveRecord::Migration def self.up add_column :categories, :lft, :integer add_column :categories, :rgt, :integer add_column :categories, :root_id, :integer # Convert existing tree to nested set with scope Category.reset_column_information # So the new root ids get saved Category.renumber_all Category.roots.each do |r| r.all_children.each do |c| c.update_attribute(:root_id, r.id) end r.update_attribute(:root_id, r.id) end end def self.down remove_column :categories, :lft remove_column :categories, :rgt remove_column :categories, :root_id end end On Feb 18, 11:45 am, Roderick van Domburg <rails-mailing-l...@andreas- s.net> wrote:> Mindtonic wrote: > > anyone have any ideas? > > You should definitely use awesome_nested_set instead of > acts_as_nested_set. The former has much cleaner code. > > If the size of your tree allows it, I would choose to recreate it using > awesome_nested_set using move_to instead of figuring out a smart > algorithm for conversion. It''ll spare you development time and guarantee > a proper conversion. > > -- > Roderick van Domburghttp://www.nedforce.com > -- > Posted viahttp://www.ruby-forum.com/.--~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe@googlegroups.com For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---
Roderick van Domburg
2009-Feb-18 18:00 UTC
Re: Converting Acts_As_Tree to Acts_As_Nested_Set
Mindtonic wrote:> Is awesome_nested_set a better choice than better_nested_set? I found > the following on the better_nested_set wiki page:Yes. Use awesome_nested_set instead.> Migrating from acts_as_tree > > In reference to migrating from acts_as_tree Krishna Dole said, �If you > have multiple trees in your table, it is a little more complicated. > You first need to give each tree scope (add a tree_id column) and then > run the above method on a member of each tree.� > > Not completely understanding that statement, I set out to implement it > in a migration. Here is my result which appears to work. In this > example, I am using a model named Categories:Never read and thought of that, but that should work great! -- Roderick van Domburg http://www.nedforce.com -- Posted via http://www.ruby-forum.com/. --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe@googlegroups.com For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---
Every time I tries to run the migration, the rake aborted saying that there is a missing attribute ''name'', which is definitely present in the model. Also, the awesome_nested_set rdocs fail to rake... rendering the concept useless as there is very little online documentation. Oh well... On Feb 18, 1:00 pm, Roderick van Domburg <rails-mailing-l...@andreas- s.net> wrote:> Mindtonic wrote: > > Is awesome_nested_set a better choice than better_nested_set? I found > > the following on the better_nested_set wiki page: > > Yes. Use awesome_nested_set instead. > > > Migrating from acts_as_tree > > > In reference to migrating from acts_as_tree Krishna Dole said, If you > > have multiple trees in your table, it is a little more complicated. > > You first need to give each tree scope (add a tree_id column) and then > > run the above method on a member of each tree. > > > Not completely understanding that statement, I set out to implement it > > in a migration. Here is my result which appears to work. In this > > example, I am using a model named Categories: > > Never read and thought of that, but that should work great! > > -- > Roderick van Domburghttp://www.nedforce.com > -- > Posted viahttp://www.ruby-forum.com/.--~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe@googlegroups.com For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---
SOLUTION: You''re not going to believe this. 1. Install the plugin 2. Write and run a migration to add `lft` and `rgt` integer columns to your model 3. Change `acts_as_tree` to `acts_as_nested_set` in your model 4. Open the Console 5. type: NameOfYourModel.rebuild! That''s it! Woah, I''ve been looking for this for weeks. I hope it helps somebody out there. On Feb 18, 1:31 pm, Mindtonic <mindto...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote:> Every time I tries to run the migration, the rake aborted saying that > there is a missing attribute ''name'', which is definitely present in > the model. Also, the awesome_nested_set rdocs fail to rake... > rendering the concept useless as there is very little online > documentation. Oh well... > > On Feb 18, 1:00 pm, Roderick van Domburg <rails-mailing-l...@andreas- > > s.net> wrote: > > Mindtonic wrote: > > > Is awesome_nested_set a better choice than better_nested_set? I found > > > the following on the better_nested_set wiki page: > > > Yes. Use awesome_nested_set instead. > > > > Migrating from acts_as_tree > > > > In reference to migrating from acts_as_tree Krishna Dole said, If you > > > have multiple trees in your table, it is a little more complicated. > > > You first need to give each tree scope (add a tree_id column) and then > > > run the above method on a member of each tree. > > > > Not completely understanding that statement, I set out to implement it > > > in a migration. Here is my result which appears to work. In this > > > example, I am using a model named Categories: > > > Never read and thought of that, but that should work great! > > > -- > > Roderick van Domburghttp://www.nedforce.com > > -- > > Posted viahttp://www.ruby-forum.com/.--~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe@googlegroups.com For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---
Mindtonic wrote:> SOLUTION: > > You''re not going to believe this. > > 1. Install the plugin > 2. Write and run a migration to add `lft` and `rgt` integer columns to > your model > 3. Change `acts_as_tree` to `acts_as_nested_set` in your model > 4. Open the Console > 5. type: NameOfYourModel.rebuild! > > That''s it! > > Woah, I''ve been looking for this for weeks. I hope it helps somebody > out there.Hi, Before migrating to awesome_nested_set, I''d like to know if moving things around happens easily. Let''s say I have the following tree: Root |- Hardware |- GPS |- Screens |- Keyboards |- Geek stuff |- iPod Let''s say I want to move GPS to Geek Stuff, how does it work? -- Posted via http://www.ruby-forum.com/.