# Advice on db/model relationships in RoR

**URL:** <https://www.ruby-forum.com/t/advice-on-db-model-relationships-in-ror/236734>\
**Category:** Rails\
**Created:** [September 29, 2013, 9:56am UTC](https://www.ruby-forum.com/t/advice-on-db-model-relationships-in-ror/236734 "2013-09-29T09:56:14Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![addis\_a](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/a/c4cdca/32.png) [@addis\_a](https://www.ruby-forum.com/u/addis_a)\
**Post date:** [September 29, 2013, 9:56am UTC](https://www.ruby-forum.com/t/advice-on-db-model-relationships-in-ror/236734/1 "2013-09-29T09:56:14Z")

</div>

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.

---

<div class="post-metadata">

**Author:** ![unknown](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/u/4bbf92/32.png) [@unknown](https://www.ruby-forum.com/u/unknown)\
**Post date:** [September 29, 2013, 10:19am UTC](https://www.ruby-forum.com/t/advice-on-db-model-relationships-in-ror/236734/2 "2013-09-29T10:19:41Z")

</div>

On 25 September 2013 11:34, [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid) 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
