0

我想用 ActiveRecord(不是纯 SQL)在 spree_products_taxons 表中创建新记录,但是:

1.9.3-head :003 > Spree::ProductsTaxon.create(product_id: 666, taxon_id: 777)
NameError: uninitialized constant Spree::ProductsTaxon

我哪里错了?

附言。在我的架构文件中:

create_table "spree_products_taxons", :id => false, :force => true do |t|
    t.integer "product_id"
    t.integer "taxon_id"
end
4

1 回答 1

1

你可以试试这样的

product = Spree::Product.find(666)
taxon = Spree::Taxon.find(777)
product.taxons << taxon
product.save
taxons = product.taxons
于 2012-09-18T10:38:07.447 回答