【发布时间】:2013-01-16 03:41:55
【问题描述】:
我有一个Brand 模型和一个Price 模型,因此:
brand.rb
class Brand < ActiveRecord::Base
attr_accessible :name, :a4_single, :a4_double, :a3_double, :two_a3_double
has_many :prices, :dependent => :destroy
end
price.rb
class Price < Brand
attr_accessible :type, :quantity, :price, :brand_id
belongs_to :brand
end
我希望能够在 每个 产品列中插入 多个 Price 记录,例如,:a4_single 中的 10 条 Price 记录,@ 中的 8 条记录987654328@,:a3_double 中有两个,:two_a3_double 中有八个。
我只是猜测上面定义的has_many关系是正确的,我真的不知道如何从这里着手。
【问题讨论】:
标签: ruby-on-rails-3 has-many belongs-to