Hi,
I want to create simple many to many association between my product and
category model. Category model currently also acts_as_tree for
navigation. The code works fine but not sure why after updating product
categories, parent category is also inserted repeatedly. This is
surprising because new record in my join model is repeating with parent
category every few minutes. here are my model code
class Category < ActiveRecord::Base
acts_as_tree :order => ‘name’
has_many :categorizations, :dependent => :destroy
has_many :products, :through => :categorizations
end
class Product < ActiveRecord::Base
has_many :categorizations, :dependent => :destroy
has_many :categories, :through => :categorizations
end
class Categorization < ActiveRecord::Base
belongs_to :product
belongs_to :category
end
I’m also pasting relevant fields from the schema to give more contexts
create_table “categories”, :force => true do |t|
t.integer “parent_id”
t.string “name”
t.datetime “created_at”
t.datetime “updated_at”
end
create_table “categorizations”, :force => true do |t|
t.integer “product_id”
t.integer “category_id”
t.datetime “created_at”
t.datetime “updated_at”
end
Any help is appreciated. Just to reiterate category assignment works but
after some times, parent category of the assigned category is inserted
repeatedly.