【发布时间】:2013-12-10 20:43:56
【问题描述】:
我有以下设置
class Category < ActiveRecord::Base
has_many :category_products
has_many :products, through: :category_products
end
class Product < ActiveRecord::Base
has_many :category_products
has_many :categories, through: :category_products
end
class CategoryProducts < ActiveRecord::Base
belongs_to :category
belongs_to :product
end
在 Rails 控制台中,我尝试使用以下命令分配 category_ids p.category_ids = [1,2](其中 p = Product.first)我得到
NameError: uninitialized constant Product::CategoryProduct
有什么建议吗?
谢谢
【问题讨论】:
-
事实证明,rails 不喜欢连接模型的“多”名称,创建了一个名为 categorization 的新模型,并且所有工作 100%
标签: ruby-on-rails-3 has-many-through