Forum: Ruby on Rails Advice on db/model relationships in RoR

0715f4db2c8d720ada0024b99a3bb791?d=identicon&s=25 unknown (Guest)
on 2013-09-29 09:56
(Received via mailing list)
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.
5f94b9b346c2aa648a80bc259978e5bc?d=identicon&s=25 Colin Law (Guest)
on 2013-09-29 10:19
(Received via mailing list)
On 25 September 2013 11:34,  <worldofproper@gmail.com> wrote:
> 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 COLLECTION

Yes, 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, COLLECTION

I 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
Please log in before posting. Registration is free and takes only a minute.
Existing account

NEW: Do you have a Google/GoogleMail, Yahoo or Facebook account? No registration required!
Log in with Google account | Log in with Yahoo account | Log in with Facebook account
No account? Register here.