This project is archived and is in readonly mode.
activerecord 2.1.0 deletion callback wont work anymore
Reported by tophe | June 25th, 2008 @ 10:12 AM
since the migration from 2.0.2 to 2.1.0. the deletion callback aren't anymore working.
i have a before_destroy, and then a after_destroy callback on a activerecord object.
in 2.0.2 it use to work we have
begin ... before_destroy ... object deletion ... commit
begin ... after_destroy ... commit
in 2.1.0 we have
begin ... before_destroy ... after_destroy ... commit.
and has in the after_destroy, we call other object destroy which run a before_destroy verifing that they don't belong to other object that dont work.
ex :
class Sale < Base
belongs_to :address
def before_destroy
raise "can't destroy sale.id = #{self.id} linked lot exist" if Lot.count(:conditions => ['idsale = ?',self.id]) >0
end
def destroyer
self.address.destroy
end
end
class Sale < Base
has_many :sale
def before_destroy
raise "can't destroy address.id = #{self.id} linked sale exist" if Sale.count(:conditions => ['idaddress = ?',self.id]) >0
end
that simple exemple use to work with ar2.0.2 but dont work anymore in ar2.1.0
Comments and changes to this ticket
-
tophe June 26th, 2008 @ 12:40 PM
- Tag set to 2.1, activerecord, callback, delete
hi guy.
I have just finded were was the probleme. and by the way that's not a bug.
in fact the relation was declared with a dependent => :destroy.
that functionality wasn't working with rails 2.0.2, and when i do the upgrade to rails 2.1.0, the dependent tag was played before, the deletion happend.
so the older code dont work anymore.
class Sale < Base
belongs_to :address,
:dependent => :destroy
def before_destroy
raise "can't destroy sale.id = #{self.id} linked lot exist" if Lot.count(:conditions => ['idsale = ?',self.id]) >0
end
i have simply remove the depend relation and everything works !
-
Jeremy Kemper June 26th, 2008 @ 09:33 PM
- State changed from new to resolved
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>