a11hard
a11hard

Reputation: 2064

How do you update a join table record with no primary keys in rails?

I have a join table that has a through association between two other tables. This table has its own rails model representation and some fields that are not the the id's of the other tables. Is it possible to update a record from the join table or should I consider creating a unique primary key?

If I try to "update_attributes" on the record I get the following error...

Unknown column 'join_table.' in 'where clause': UPDATE `join_table` SET `join_table_attribute` = 1 WHERE `join_table`.`` IS NULL

Upvotes: 0

Views: 589

Answers (1)

Mori
Mori

Reputation: 27789

You can use update_all for that, e.g.:

JoinModel.update_all('join_table_attribute = 1', 'join1_id = 42, join2_id = 24')

Upvotes: 2

Related Questions