1
我需要有一个许多人对产品和类别进行连接需要
,所以我有
class Category < ActiveRecord::Base
has_many :categorizations
has_many :products, :through => :categorizations
end
class Product < ActiveRecord::Base
has_many :categorizations
has_many :categories, :through => :categorizations
end
一对多的关系分类已的结构是这样的
* PRODUCT_ID (primary key, foreign key to PRODUCTS)
* CATEGORY_ID (primary key, foreign key to CATEGORIES)
* QUANTITY
在我的控制器
我正在创建此类别和产品
@new_product = Product.create :name => "test"
@new_category = Category.create :name => "test category"
如何连接这两个,我如何设置数量
与一对多如果我的记忆正确地为我服务,这是如何完成的。但随着多对多通过我失去了
@ new_product.catagory < < @new_category