Srdjan M. wrote:
From what you wrote, it doesn’t look like you need to. The HABTM
association should work through that table as it is.
it does work, sort of. Whenever I reference a category through the
relationship I get it as a readonly object.
p = Product.find :first
c = p.categories.first #c is readonly and it cannot be modified
This problem goes away when one sets the primary key as
primary key (category_id, product_id)
through SQL code.
I hoped that there would be a rails way to do the primary key setting.
I think what’s going on is that your migration is adding an “id” field
as the primary key. That’s the default behavior of the create_table
method. Look at your table’s schema in an SQL tool to see what’s going
on there. To disable generation of an “id” field, add a “:id => false”
option to create_table.
If for some reason you still need to set the primary key to the
combination of the foreign keys, the migration method is:
add_index(:categories_products, [:category_id, :product_id], :unique =>