John Smith wrote:> I have a User model, a Favourite model, a Film model and a Song model.
> I would like o achieve user favourite films and user favourte songs with
> databse associations, using just a Favourite model. Which will be the
> best way? How should define those models?
I assume the best way will be something like that:
create_table :favorites do |t|
t.integer :user_id
t.references :favorable, :polymorphic => true
t.timestamps
end
User.rb
has_many :favorites
has_many :favorables, :through => :favorites
Film.rb
has_many :favorites, :as => :favorable
has_many :favoriting_users, :through => :favorites, :source => :user
Song.rb
has_many :favorites, :as => :favorable
has_many :favoriting_users, :through => :favorites, :source => :user
--
Posted via http://www.ruby-forum.com/.