All,
I’ve read about twelve different articles and I’ve yet to find a
consistent solution to my conundrum.
I have a ‘people’ table and an associated ‘person’ model object.
I have a ‘preferences’ table and an associated ‘preference’ model
object.
People is as trivial as: id, first_name, last_name.
Preferences - also trivial: id, name
Now I need to create a nice join table (with a ‘value’ attribute)…my
question is: do I name it ‘people_preferences’ or ‘person_preferences’.
I’m inclined to the latter. The definition is pretty obvious:
person_id, preference_id, value.
Next question, assuming we go wtih person_preferences and I generate the
rails model: ./script/generate model person_preference, I’m thinking my
model associations look something like the following - can
someone/anyone validate?
class Person
…
has_many :person_preferences, :dependent => :destroy
has_many :preferences, :through => :person_preferences
…
end
class Preference
…
has_many :person_preferences, :dependent => :destroy
has_many :people, :through => :person_preferences
…
end
class Person_Preference
…
belongs_to :person
belongs_to :person
…
end
Interacting with the model would look like:
@person.person_preferences.each{|pref| puts “#{pref.preference.name}” :
#{pref.value}}
Thoughts? Am I crazy? Way off the mark?? TIA for any help!