Shane Sherman
2005-Jun-10 22:28 UTC
has_and_belongs_to_many issues with before_destroy callback
Has anyone noticed that the row in the join table in a has_and_belongs_to_many relationship is deleted *before* the before_destroy callback gets triggered? class Album < ActiveRecord::Base has_and_belongs_to_many :rankings before_destroy :delete_rankings private def delete_rankings info.logger "IN DELETE RANKINGS" end end class Ranking < ActiveRecord::Base has_and_belongs_to_many :albums end If I have an album with rankings, and I call album.destroy with full logging turn on, I see this : [4;35mSQL (0.000000)[m [0;37mDELETE FROM albums_rankings WHERE album_id = 10[m IN DELETE RANKINGS This does not seem right. There is some logic I want to implement when rankings get destroyed, and I am forced to use triggers to do it.
Michael Koziarski
2005-Jun-10 22:31 UTC
Re: has_and_belongs_to_many issues with before_destroy callback
On 6/11/05, Shane Sherman <wtf242-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote:> Has anyone noticed that the row in the join table in a > has_and_belongs_to_many relationship is deleted *before* the > before_destroy callback gets triggered? > > > class Album < ActiveRecord::Base > has_and_belongs_to_many :rankings > before_destroy :delete_rankings > > private > def delete_rankings > info.logger "IN DELETE RANKINGS" > end > end > > class Ranking < ActiveRecord::Base > has_and_belongs_to_many :albums > end > > > If I have an album with rankings, and I call album.destroy with full > logging turn on, I see this : > > [4;35mSQL (0.000000)[m [0;37mDELETE FROM albums_rankings WHERE album_id = 10[m > IN DELETE RANKINGS > > This does not seem right. There is some logic I want to implement when > rankings get destroyed, and I am forced to use triggers to do it.You''ve found http://dev.rubyonrails.com/ticket/1183, It''s marked for 1.0 at present> _______________________________________________ > Rails mailing list > Rails-1W37MKcQCpIf0INCOvqR/iCwEArCW2h5@public.gmane.org > http://lists.rubyonrails.org/mailman/listinfo/rails >-- Cheers Koz