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/.

--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups "Ruby 
on Rails: Talk" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to 
[email protected]
For more options, visit this group at 
http://groups.google.com/group/rubyonrails-talk?hl=en
-~----------~----~----~----~------~----~------~--~---

Reply via email to