【发布时间】:2012-08-13 12:52:56
【问题描述】:
我有一个关于 Mongoid 关联的新手问题。我有这两个模型
class Manufacturer
include Mongoid::Document
field :name, type: String
field :url, type: String
has_many :products
end
和
class Product
include Mongoid::Document
field :manufacturer_name, type :String
field :model, type: String
field :price, type: Float
belongs_to :manufacturer
end
现在我创建了一家新公司:
man = Manufacturer.create name: 'Flower Power Companies', url: 'www.flowerpower.com'
还有一个新产品:
prod = Product.create manufacturer_name: what_comes_here, model: 'Foo0815', price: '19.90'
如何将 prod.manufacturer_name 引用到 man.name?如果 man.name 将被更改,则 prod.manufacturer_name 应自动更改。
【问题讨论】:
标签: ruby-on-rails associations mongoid