Oleg Pasko
Oleg Pasko

Reputation: 2911

spree_products_taxons record creating in RoR: Spree

I want to create new record in spree_products_taxons table with ActiveRecord (not with pure SQL), but:

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

Where am i wrong?

ps. In my schema file:

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

Upvotes: 0

Views: 210

Answers (1)

madmed
madmed

Reputation: 636

You can try something like this

product = Spree::Product.find(666)
taxon = Spree::Taxon.find(777)
product.taxons << taxon
product.save
taxons = product.taxons

Upvotes: 1

Related Questions