I've got a model named
feedback with characteristics, rating and review. A
product could have a feedback, a
appointment could have a feedback, a
user could have a feedback.
I possibly could add individual fields, like user_id, product_id, appointment_id within the feedbacks table, but that doesn't appear to become a excellent scalable solution. Another option i believe is by using a generalized, reference_id area, along with a reference_model area which may be populated using the model title transformed into string, after which I possibly could by hand interpret when the id joined in reference_id goes to some user, product or perhaps an appointment.
What will be the easiest way of carrying out associating each feedback with any of the 3 models, in a with time?
You need to find out about Polymorphic Associations.
class Picture < ActiveRecord::Base belongs_to :imageable, :polymorphic => true end class Employee < ActiveRecord::Base has_many :pictures, :as => :imageable end class Product < ActiveRecord::Base has_many :pictures, :as => :imageable end
You will find a pleasant RailsCast.