Ruby Active Record Relational -
Ruby Active Record Relational -
still newbie here, still couldn't logic right.
currently, have:
user has many products. product has 1 user cost attribute.i trying add together on:
user can offer 1 cost on product sold user. user can offer cost on multiple products. a product can have many offered cost multiple users.i have come out with:
class user < activerecord::base has_many :products has_many :offered_prices end class product < activerecord::base belongs_to :user has_many :offered_prices end
this have done far. still doesn't seem quite right rather confused @ same time. help much appreciated! :)
define 3 models:
user | offeredprice | product
the association amongst them be:
class user < activerecord::base has_many :products has_many :offered_prices, through: :products end class offeredprice < activerecord::base belongs_to :user belongs_to :product # create sure user can offer cost 1 time against product validates_uniqueness_of :price, scope: [:user, :product] end class product < activerecord::base has_many :offered_prices has_many :user, through: :offered_prices end
ruby-on-rails ruby activerecord associations
Comments
Post a Comment