This project is archived and is in readonly mode.
HABTM association is being destroyed before the before_destory callbacks are executed
-
Ed4
This looks to me like a serious issue, because it's no longer possible to use a before_destroy callback to check for the existence of associated HABTM records. In the following example, the callback never sees any associated lessons:
class Student < ActiveRecord::Base has_and_belongs_to_many :lessons before_destroy {|s| s.lessons.empty? } endThis worked in Rails 2.x, and broke when I tried to upgrade to Rails 3.
I tried defining the callback before the association to tweak their order, but it doesn't solve the problem.
-
Ed4
Here is a patch to fix this, including a new unit test. There was an existing unit test that actually tests for the wrong behavior (it forces the deletion of association records before entering the before_destroy callback), so I updated it as well.
-
Repository
- State changed from new to resolved
(from [909588d964bf27f20142a0b4d57890114a8d4a7a]) Fixing ordering of HABTM association deletion [#6191 state:resolved]
Signed-off-by: Santiago Pastorino santiago@wyeworks.com
https://github.com/rails/rails/commit/909588d964bf27f20142a0b4d5789...
