This project is archived and is in readonly mode.

#5674 ✓committed
Steve Purcell

Regression: HABTM deletion fails when join table has foreign keys

Reported by Steve Purcell | September 21st, 2010 @ 11:19 AM

Given models One and Two, where One declares "has_and_belongs_to_many :twos", it's no longer possible to delete an instance of One if there are corresponding rows in the join table (ones_twos) and that join table has a foreign key on one_id.

In Rails < 3, the rows in the join table would be deleted before the parent object, but in 3.0 the join table rows appear to be deleted afterwards, and so any foreign key will block the deletion of the parent object -- dropping the foreign keys makes everything work, but this is an extremely undesirable workaround.

There's no obvious option for habtm to fix this behavior, and no mention of related changes in the Rails 3 Guides, so I can only guess that this is a regression.

The problem presents itself with both PostgreSQL 8.4 and 9.0, but would also presumably affect other DBs with foreign key support.

Comments and changes to this ticket

Create your profile

Help contribute to this project by taking a few moments to create your personal profile. Create your profile »

<h2 style="font-size: 14px">Tickets have moved to Github</h2>

The new ticket tracker is available at <a href="https://github.com/rails/rails/issues">https://github.com/rails/rails/issues</a>

Referenced by

Pages