worldofproper-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org
2013-Sep-25 10:34 UTC
Advice on db/model relationships in RoR
Hi there. I''m making my first rails app and taking Hartl''s tutorial app as my starting point. All the features he implements are things I want. Primarily the site wants to be a collection organising site. I''ll be adding a table of ITEMS, and USERS can add those ITEMS to their collection or to their wantlist. What I''m trying to decide is where best to put the "who has what" information. It seems to me that doing it all in the USERS or ITEMS table might be a bit cumbersome. For instance an ITEM "has many" USERS with a long list of them, or a USER "has many" ITEMS, again with a long list. Would it be better to use "has many through" with an OWNERSHIP or COLLECTION model/table? I''m thinking along the lines of 1, USER 5, ITEM 322, WANTLIST 2, USER 9, ITEM 27, COLECTION 3, USER 6, ITEM 90, COLLECTION etc If this is a better idea would it make more sense to give WANTLIST a seperate model/table? I''m trying to work out what would be the most efficient way of doing it. They want to be easily indexable so that you can have "USER has 378 ITEMS" and the like. Any pointers much appreciated. -- You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To unsubscribe from this group and stop receiving emails from it, send an email to rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org To view this discussion on the web visit https://groups.google.com/d/msgid/rubyonrails-talk/e35d0b3b-50b0-4fa1-be7a-b7f064b398a2%40googlegroups.com. For more options, visit https://groups.google.com/groups/opt_out.
On 25 September 2013 11:34, <worldofproper-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote:> Hi there. I''m making my first rails app and taking Hartl''s tutorial app as > my starting point. All the features he implements are things I want. > > Primarily the site wants to be a collection organising site. I''ll be adding > a table of ITEMS, and USERS can add those ITEMS to their collection or to > their wantlist. > > What I''m trying to decide is where best to put the "who has what" > information. It seems to me that doing it all in the USERS or ITEMS table > might be a bit cumbersome. For instance an ITEM "has many" USERS with a long > list of them, or a USER "has many" ITEMS, again with a long list.If a user can have many items, and each item can be associated with many users then neither of those will work.> > Would it be better to use "has many through" with an OWNERSHIP or COLLECTIONYes, if the relationship requires it (see above).> model/table? > I''m thinking along the lines of > 1, USER 5, ITEM 322, WANTLIST > 2, USER 9, ITEM 27, COLECTION > 3, USER 6, ITEM 90, COLLECTIONI don''t understand what WANTLIST COLECTION and COLLECTION mean here.> etc > > If this is a better idea would it make more sense to give WANTLIST a > seperate model/table? > > I''m trying to work out what would be the most efficient way of doing it. > They want to be easily indexable so that you can have "USER has 378 ITEMS" > and the like.current_user.items.count Colin -- You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To unsubscribe from this group and stop receiving emails from it, send an email to rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org To view this discussion on the web visit https://groups.google.com/d/msgid/rubyonrails-talk/CAL%3D0gLsMH6MH407GWwv%2BjtSzHkf73aPEBohLv8rO1fdzhRyWbg%40mail.gmail.com. For more options, visit https://groups.google.com/groups/opt_out.