I have two models: User and HairColor. A user has only one hair color, but can have many hair color preferences. What's the best way to model this?
Here's what I started to do:
#models/user.rb
class User < ActiveRecord::Base
belongs_to :hair_color
has_many :preferences,
has_many :hair_colors, :through => :preferences
end
#models/hair_color.rb
class HairColor < ActiveRecord::Base
has_many :users
end
#models/preference.rb
class Preference < ActiveRecord::Base
belongs_to :user
belongs_to :hair_color
end
Is using has_many :through the right approach? Also what if I want to extend this to other attributes such as "eye color"? (A user has one eye color, but can prefer many eye colors"