ruby on rails - How to setup the associations for an "Options" model? -


if had had models store, product, user , price following associations

class user < activerecord::base   has_many :products   has_many :stores   has_many :prices end  class store < activerecord::base   belongs_to :user   has_many :prices end  class product < activerecord::base   belongs_to :user   has_many :prices end  class price < activerecord::base   belongs_to :user   belongs_to :product   belongs_to :store end  class estate < activerecord::base   belongs_to :user end 

and want create option model holds models specific option type things like, if estate has backyard, swimming pool, tennis court or price has deal, discount or buy 1 1 free. done polymorphic association? i'm doing don't have create option model each model , can have 1 model new options want add. correct way go this?

if use polymorphic option model, fields same each class/record object belongs to. don't think want since deal doesn't have swimming pool , estate isn't buy-one-get-one (i wish!).

i using rails 3.2 , activerecord::store feature. this, add single text column model(s) (call "options") , can define options need.

class estate < activerecord::base   belongs_to :user   store :options, accessors: [ :backyard, :pool, :tennis, :butler, :wine_cellar ] end  estate = estate.new estate.pool = true estate.options[:number_of_sharks] = 3 # attributes not defined accessors work 

Comments

Popular posts from this blog

java - Play! framework 2.0: How to display multiple image? -

gmail - Is there any documentation for read-only access to the Google Contacts API? -

php - Controller/JToolBar not working in Joomla 2.5 -