Forum: Ruby on Rails Multiple Many-to-Many relationship on same both modles???

Announcement (2017-05-07): www.ruby-forum.com is now read-only since I unfortunately do not have the time to support and maintain the forum any more. Please see rubyonrails.org/community and ruby-lang.org/en/community for other Rails- und Ruby-related community platforms.
Aed326335b876b6baf65016450c00cfa?d=identicon&s=25 Mister Yu (Guest)
on 2007-07-31 00:45
(Received via mailing list)
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.
D69d23d8e811e8ab2a8593380d6ede63?d=identicon&s=25 Jeff Emminger (jemminger)
on 2007-07-31 04:47
(Received via mailing list)
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
This topic is locked and can not be replied to.