Lighthouse has a new layout. Prefer the old one? Return to the old layout, and switch back any time from the link at the top of each page.

This project is archived and is in readonly mode.

activerecord 2.1.0 deletion callback wont work anymore

#482

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

Reported by tophe · June 25th, 2008 @ 10:12 AM

State: resolved
Milestone: none
Assigned to: Tobias Lütke Tobias Lütke
Importance: none

Activity

  1. tophe
    tophe
    • 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 !

    June 26th, 2008 @ 12:40 PM

  2. Jeremy Kemper
    Jeremy Kemper
    • State changed from new to resolved

    June 26th, 2008 @ 09:33 PM