Hi Everyone, I''m stumped. Imagine I have a bunch of assets. I want to be able to group them together (like in graphics programs), and then be able to group them into further groups. What is the best way to do this? 1) I could have two models, Asset and AssetGroup, where Asset has_a url, and AssetGroup has_many Assets and has_many AssetGroups. 2) I could have one model: Asset, which has_a url and has_many Assets, where if it has a url it''s a "leaf" asset, and if it has some assets, it''s a "branch." It could have a type field, too. 3) Something else? The reason this is difficult is because I want to have other models be able to contain either an Asset or an Asset group, and treat them as the roughly the same thing. How would you go about doing this? Thanks ~sean --~--~---------~--~----~------------~-------~--~----~ 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 -~----------~----~----~----~------~----~------~--~---
On Oct 2, 9:52 am, "Sean Clark Hess" <seanh...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote:> Hi Everyone, > I''m stumped. Imagine I have a bunch of assets. I want to be able to group > them together (like in graphics programs), and then be able to group them > into further groups. > > What is the best way to do this? > > 1) I could have two models, Asset and AssetGroup, where Asset has_a url, and > AssetGroup has_many Assets and has_many AssetGroups. > > 2) I could have one model: Asset, which has_a url and has_many Assets, where > if it has a url it''s a "leaf" asset, and if it has some assets, it''s a > "branch." It could have a type field, too. > > 3) Something else? > > The reason this is difficult is because I want to have other models be able > to contain either an Asset or an Asset group, and treat them as the roughly > the same thing. > > How would you go about doing this? > > Thanks > ~seanacts_as_tree might work nicely for this. http://wiki.rubyonrails.org/rails/pages/ActsAsTree http://api.rubyonrails.com/classes/ActiveRecord/Acts/Tree/ClassMethods.html --~--~---------~--~----~------------~-------~--~----~ 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 -~----------~----~----~----~------~----~------~--~---
Thanks twice-over, Erol :) I''ll look at those to see how they work On Wed, Oct 1, 2008 at 9:20 PM, Erol Fornoles <erol.fornoles-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org>wrote:> > On Oct 2, 9:52 am, "Sean Clark Hess" <seanh...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote: > > Hi Everyone, > > I''m stumped. Imagine I have a bunch of assets. I want to be able to group > > them together (like in graphics programs), and then be able to group them > > into further groups. > > > > What is the best way to do this? > > > > 1) I could have two models, Asset and AssetGroup, where Asset has_a url, > and > > AssetGroup has_many Assets and has_many AssetGroups. > > > > 2) I could have one model: Asset, which has_a url and has_many Assets, > where > > if it has a url it''s a "leaf" asset, and if it has some assets, it''s a > > "branch." It could have a type field, too. > > > > 3) Something else? > > > > The reason this is difficult is because I want to have other models be > able > > to contain either an Asset or an Asset group, and treat them as the > roughly > > the same thing. > > > > How would you go about doing this? > > > > Thanks > > ~sean > > acts_as_tree might work nicely for this. > > http://wiki.rubyonrails.org/rails/pages/ActsAsTree > http://api.rubyonrails.com/classes/ActiveRecord/Acts/Tree/ClassMethods.html > > >--~--~---------~--~----~------------~-------~--~----~ 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 -~----------~----~----~----~------~----~------~--~---