error in has_many :through

When I was using habtm

product.categories.replace(…category objects) was working fine

But when I started using has_many :through

other relations are working, but I am not able to do

product.categories.replace (…category objects)

What is the solution then?

Regards, Anil Wadghule

What is the solution then?

Can you post your relationship declarations for the product and category models?

Steve

Hi Steve,

These are relationship declarations for product, category and CategoriesProduct models!

class Product < ActiveRecord::Base

has_many :categories_products has_many :categories, :through => :categories_products

class Category < ActiveRecord::Base

has_many :categories_products has_many :products, :through => :categories_products

class CategoriesProduct < ActiveRecord::Base belongs_to :category belongs_to :product end

Thanks Josh,

I did the same.

Regards, Anil Wadghule