Double Relationship on 2 Entities

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!

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
[email protected]
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/.


Ryan B.