我有一个关于 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 应自动更改。