This project is archived and is in readonly mode.
Regression: HABTM deletion fails when join table has foreign keys
-
Steve Purcell
The attached patch to schema.rb causes the relevant tests to fail with the problem as described.
-
gnufied
Verified. Problem exists. A quick workaround is, to have ON DELETE CASCADE on such foreign keys.
-
Steve Purcell
Indeed, though it's generally recommended to avoid ON DELETE CASCADE, since records can disappear without Rails knowing. For example, adding ON DELETE CASCADE to developers_projects breaks 2 cases in NestedScopingTest.
-
gnufied
- Tag changed from 3.0, activerecord, habtm to 3.0, activerecord, habtm, patch
Attached patch fixes the problem and updates the failing test cases to accomodate the new behavior.
-
Aaron Patterson
- State changed from new to committed
- Importance changed from to Low
I've committed this, thanks!
-
Steve Purcell
Cool, thanks! -- will that fix get into 3.0.1? I don't see it in the 3-0-stable branch, but maybe the plan is to merge master for that release.
-
Aaron Patterson
No! I made a mistake. I was going to merge to the 3-0-stable branch, but I forgot! Thanks for reminding me. It should be on the 3-0-stable branch now. Thanks!
-
Steve Purcell
In case it helps anyone while we wait for 3.0.1, I've posted the monkey patch initializer I'm using to work around this issue here:
-
Evgeniy Dolzhenko
The problem with the patch that was committed is that now
before_destroycallbacks on the models with HABTM associations don't see the corresponding associations. For example if you wanted to prevent models referenced by HABTM from being destroyed you can't do that withbefore_destroycallback any longer. -
Hemant Kumar
Can you get a test case attached, I will see what I can do to fix the problem.
