Hello, I''m relatively new to Rails and had a question about how to best set up relationships between a few of my objects. Right now, I''ve got the following model objects: Transmission List Technique A Transmission contains many Lists and a List contains many Techniques. So far so good. However, a List can also contain many other Lists (a kind of "sub list") and these "sub lists" will also contain many Techniques. So, the relation between Transmissions and Lists is pretty straightforward, as is the relationship between Techniques and Lists. The problem I''m having is in regards to this recursive relationship between Lists and their child Lists. A list could contain: 1) Only techniques (i.e. no other Lists) 2) A combination of Techniques and Lists (each List with its own Techniques) 3) Only child Lists (i.e. no Techniques as direct children) I''m not sure if it makes things easier or not, but a given List will never be a parent to other Lists AND a child of another List...only one or the other. In other words, if ListA has a child, ListB, then ListB will never really exist outside of the context of ListA. After writing this out, it''s even more confusing than before. I hope someone can point me in the right direction with this. Thanks in advance! -Brian --~--~---------~--~----~------------~-------~--~----~ 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 -~----------~----~----~----~------~----~------~--~---
Take a look at the acts_as_list plugin - I think it will solve your problem with the List model. -Dan Manges On Jun 27, 1:47 pm, bmcelhany <bmcelh...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote:> Hello, I''m relatively new to Rails and had a question about how to > best set up relationships between a few of my objects. Right now, I''ve > got the following model objects: > > Transmission > List > Technique > > A Transmission contains many Lists and a List contains many > Techniques. So far so good. However, a List can also contain many > other Lists (a kind of "sub list") and these "sub lists" will also > contain many Techniques. > > So, the relation between Transmissions and Lists is pretty > straightforward, as is the relationship between Techniques and Lists. > The problem I''m having is in regards to this recursive relationship > between Lists and their child Lists. A list could contain: > > 1) Only techniques (i.e. no other Lists) > 2) A combination of Techniques and Lists (each List with its own > Techniques) > 3) Only child Lists (i.e. no Techniques as direct children) > > I''m not sure if it makes things easier or not, but a given List will > never be a parent to other Lists AND a child of another List...only > one or the other. In other words, if ListA has a child, ListB, then > ListB will never really exist outside of the context of ListA. > > After writing this out, it''s even more confusing than before. I hope > someone can point me in the right direction with this. Thanks in > advance! > > -Brian--~--~---------~--~----~------------~-------~--~----~ 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 for the suggestion, Dan. I''ve used acts_as_list a bit in another project...I was under the impression that it''s primary purpose was to add ordering functionality to an object. I guess the bottom line is that, when I add (or edit) one of my List objects, I need to be able to specify that it is a child of either a Transmission object (effectively making it a top-level List) or of another List object (effectively making it a child List). It would never be a child of both...only one or the other. They way I''m thinking of doing it is having two columns in my table: transmission_id and parent_id. If the List object I''m adding "belongs" to a Transmission, then the transmission_id field would be populated and the parent_id field would be null. If the List object is a child list of a parent List object, then the parent_id would have a value and the transmission_id field would be null. Doesn''t seem like the cleanest solution, but I think it may work. Is there a better way to do this? Thanks! On Jun 28, 6:45 am, Dan Manges <daniel.man...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote:> Take a look at the acts_as_list plugin - I think it will solve your > problem with the List model. > > -Dan Manges > > On Jun 27, 1:47 pm,bmcelhany<bmcelh...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote: > > > Hello, I''m relatively new to Rails and had a question about how to > > best set up relationships between a few of my objects. Right now, I''ve > > got the following model objects: > > > Transmission > > List > > Technique > > > A Transmission contains many Lists and a List contains many > > Techniques. So far so good. However, a List can also contain many > > other Lists (a kind of "sub list") and these "sub lists" will also > > contain many Techniques. > > > So, the relation between Transmissions and Lists is pretty > > straightforward, as is the relationship between Techniques and Lists. > > The problem I''m having is in regards to this recursive relationship > > between Lists and their child Lists. A list could contain: > > > 1) Only techniques (i.e. no other Lists) > > 2) A combination of Techniques and Lists (each List with its own > > Techniques) > > 3) Only child Lists (i.e. no Techniques as direct children) > > > I''m not sure if it makes things easier or not, but a given List will > > never be a parent to other Lists AND a child of another List...only > > one or the other. In other words, if ListA has a child, ListB, then > > ListB will never really exist outside of the context of ListA. > > > After writing this out, it''s even more confusing than before. I hope > > someone can point me in the right direction with this. Thanks in > > advance! > > > -Brian--~--~---------~--~----~------------~-------~--~----~ 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 -~----------~----~----~----~------~----~------~--~---
Oops. I meant to suggest acts_as_tree. Your solution sounds good. Dan On Jun 28, 2008, at 1:55 PM, bmcelhany <bmcelhany-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote:> > Thanks for the suggestion, Dan. I''ve used acts_as_list a bit in > another project...I was under the impression that it''s primary purpose > was to add ordering functionality to an object. > > I guess the bottom line is that, when I add (or edit) one of my List > objects, I need to be able to specify that it is a child of either a > Transmission object (effectively making it a top-level List) or of > another List object (effectively making it a child List). It would > never be a child of both...only one or the other. > > They way I''m thinking of doing it is having two columns in my table: > transmission_id and parent_id. If the List object I''m adding "belongs" > to a Transmission, then the transmission_id field would be populated > and the parent_id field would be null. If the List object is a child > list of a parent List object, then the parent_id would have a value > and the transmission_id field would be null. > > Doesn''t seem like the cleanest solution, but I think it may work. Is > there a better way to do this? > > Thanks! > > On Jun 28, 6:45 am, Dan Manges <daniel.man...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote: >> Take a look at the acts_as_list plugin - I think it will solve your >> problem with the List model. >> >> -Dan Manges >> >> On Jun 27, 1:47 pm,bmcelhany<bmcelh...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote: >> >>> Hello, I''m relatively new to Rails and had a question about how to >>> best set up relationships between a few of my objects. Right now, >>> I''ve >>> got the following model objects: >> >>> Transmission >>> List >>> Technique >> >>> A Transmission contains many Lists and a List contains many >>> Techniques. So far so good. However, a List can also contain many >>> other Lists (a kind of "sub list") and these "sub lists" will also >>> contain many Techniques. >> >>> So, the relation between Transmissions and Lists is pretty >>> straightforward, as is the relationship between Techniques and >>> Lists. >>> The problem I''m having is in regards to this recursive relationship >>> between Lists and their child Lists. A list could contain: >> >>> 1) Only techniques (i.e. no other Lists) >>> 2) A combination of Techniques and Lists (each List with its own >>> Techniques) >>> 3) Only child Lists (i.e. no Techniques as direct children) >> >>> I''m not sure if it makes things easier or not, but a given List will >>> never be a parent to other Lists AND a child of another List...only >>> one or the other. In other words, if ListA has a child, ListB, then >>> ListB will never really exist outside of the context of ListA. >> >>> After writing this out, it''s even more confusing than before. I hope >>> someone can point me in the right direction with this. Thanks in >>> advance! >> >>> -Brian > >--~--~---------~--~----~------------~-------~--~----~ 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 -~----------~----~----~----~------~----~------~--~---
KathysKode-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org
2008-Jun-29 15:00 UTC
Re: Complex/nested relationships
Brian, If you ever get your complex ''nested'' relationships to work, I''d love to hear how. I recall years ago when I worked in manufacturing bill of materials (BOM''s) we accomplished the same thing by setting a ''nesting level'' and using this to calculate the product tree. If you ever got it WRONG the stack overflows were scary and we''d have to turn off the machine. Kathleen On Jun 27, 12:47 pm, bmcelhany <bmcelh...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote:> Hello, I''m relatively new to Rails and had a question about how to > best set up relationships between a few of my objects. Right now, I''ve > got the following model objects: > > Transmission > List > Technique > > A Transmission contains many Lists and a List contains many > Techniques. So far so good. However, a List can also contain many > other Lists (a kind of "sub list") and these "sub lists" will also > contain many Techniques. > > So, the relation between Transmissions and Lists is pretty > straightforward, as is the relationship between Techniques and Lists. > The problem I''m having is in regards to this recursive relationship > between Lists and their child Lists. A list could contain: > > 1) Only techniques (i.e. no other Lists) > 2) A combination of Techniques and Lists (each List with its own > Techniques) > 3) Only child Lists (i.e. no Techniques as direct children) > > I''m not sure if it makes things easier or not, but a given List will > never be a parent to other Lists AND a child of another List...only > one or the other. In other words, if ListA has a child, ListB, then > ListB will never really exist outside of the context of ListA. > > After writing this out, it''s even more confusing than before. I hope > someone can point me in the right direction with this. Thanks in > advance! > > -Brian--~--~---------~--~----~------------~-------~--~----~ 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 -~----------~----~----~----~------~----~------~--~---