Multiple Many-to-Many relationship on same both modles?


#1

Hi i am still very new to ROR, i hope you can help me with this
problem.

i have two modles, Place and User

users plant to go to places
users have been to places
users live in the places

these are 3 relationships. how do i write “has_many” statement to make
ROR take care them for me?

or i have to write my own codes for them?

thanks.


#2

i’m still new too, but i think one way is to make join models
representing each relationship:

e.g.

make a migration:
def self.up
create_table :planned_places do |t|
t.column :place_id, :integer
t.column :user_id, :integer
end
create_table :visited_places do |t|
t.column :place_id, :integer
t.column :user_id, :integer
end
create_table :lived_places do |t|
t.column :place_id, :integer
t.column :user_id, :integer
end
end

then in your model;
has_many :planned_places
has_many :visited_places
has_many :lived_places