# Double Relationship on 2 Entities

**URL:** <https://www.ruby-forum.com/t/double-relationship-on-2-entities/123418>\
**Category:** Rails\
**Created:** [December 17, 2007, 3:03pm UTC](https://www.ruby-forum.com/t/double-relationship-on-2-entities/123418 "2007-12-17T15:03:21Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![mex23](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/m/e47774/32.png) [@mex23](https://www.ruby-forum.com/u/mex23)\
**Post date:** [December 17, 2007, 3:03pm UTC](https://www.ruby-forum.com/t/double-relationship-on-2-entities/123418/1 "2007-12-17T15:03:21Z")

</div>

Ok,  
i have a little question.

I am developing an app and writing down the schema for my database i  
have this 2 entities (we call them like this in italian, don’t know the  
right word in english, sorry).

USER and RESOURCE

An user can submit a resource. So that’s a one-to-many relationship with  
a simple has\_many :resources and belongs\_to :user

I then want users to have favourites Resources. So that’s a many-to-many  
relationship but on the same entities as before!

How should i handle that?  
Should i create a favourite table with user\_id and resource\_id and then  
write something like: has\_many\_and\_belongs\_to :user, throught  
:favourite?  
Should i use the join\_table option?  
Should i change something on the user and resource tables?

Feel free to give your suggestions! Thank you!

---

<div class="post-metadata">

**Author:** ![mex23](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/m/e47774/32.png) [@mex23](https://www.ruby-forum.com/u/mex23)\
**Post date:** [December 17, 2007, 11:37pm UTC](https://www.ruby-forum.com/t/double-relationship-on-2-entities/123418/2 "2007-12-17T23:37:45Z")

</div>

has\_and\_belongs\_to\_many :favourite\_resources, :class\_name =\> “Resource”,  
:join\_table =\> “resources\_users”

Try that out.

On Dec 18, 2007 12:33 AM, Stefano Bernardi  
[removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid)  
wrote:

> An user can submit a resource. So that’s a one-to-many relationship with  
> Should i change something on the user and resource tables?
> 
> ## Feel free to give your suggestions! Thank you!
> 
> Posted via [http://www.ruby-forum.com/](http://www.ruby-forum.com/).
> 
> >

–  
Ryan B.

> **[frozenplague.net](http://www.frozenplague.net)**
>
> This domain may be for sale!
