I need to have a many to many relationship for products and categories
so i have
class Category < ActiveRecord::Base
has_many :categorizations
has_many :products, :through => :categorizations
end
class Product < ActiveRecord::Base
has_many :categorizations
has_many :categories, :through => :categorizations
end
the structure of categorizations is this
* PRODUCT_ID (primary key, foreign key to PRODUCTS)
* CATEGORY_ID (primary key, foreign key to CATEGORIES)
* QUANTITY
in my controller i am creating the category and product by this
@new_product = Product.create :name => "test"
@new_category = Category.create :name => "test category"
how do I connect these two and how do i set the quantity
with one to many if my memory serves me correctly this is how its done. But with the many to many through i am lost
@new_product.catagory << @new_category