Re: Order of before_delete trigger in docs

[prev] [thread] [next] [Date index for 2005/06/27]

From: William Ross
Subject: Re: Order of before_delete trigger in docs
Date: 14:03 on 27 Jun 2005
On 27 Jun 2005, at 13:35, Marius Feraru wrote:

> <snip>

> I made a simple example using two classes: "Actors" and "Roles". Let's
> say each Actor may have multiple (has_many) Roles and a Role is
> occupied by a single (has_a) Actor. Now, presuming that each Role must
> be occupied, we have to disable removing Actors that have some
> Roles attributed to themselves. Hence, using a before_delete  
> trigger on
> Actors should do the trick, but... run the test script :)

You (and Bill) are right: the documentation is out of date.

Triggers for a particular point are executed in order of declaration,  
and one of the consequences of calling has_many(...) is to declare a  
before_delete trigger to handle the cascading delete. If you want to  
use a before_delete method to interfere with cascading deletion, you  
have to declare it before you declare the relationship. I guess this  
has been true ever since relationships were factored out.

If you change your test script so that the add_trigger calls come  
before the corresponding has_a calls, I believe you'll find that it  
works properly.


will







>
> a) ./cdbi-test.pl
>  ^ should work as expected
> b) ./cdbi-test.pl 1
>  ^ fails, as triggers chain (not so bad) in reverse order (definitely
>    bad).








> - -- Marius Feraru                                   http:// 
> www.altblue.com/
> "It isn't easy being the parent of a three-years-old.
>  However, it's a pretty small price to pay for having somebody
>  around the house who understands computers."
> -----BEGIN PGP SIGNATURE-----
>
> iD8DBQFCv/Kdn0ZKufYp8iURAsogAJ9E8ZPl1GZa5mxWrxhpXFSYWwcKywCbBDVk
> 9seNXrBVOeZ4OLpN3LHDcgU=
> =0Ijs
> -----END PGP SIGNATURE-----
> <cdbi-test.pl>

(message missing)

Order of before_delete trigger in docs
Bill Moseley 17:32 on 26 Jun 2005

Re: Order of before_delete trigger in docs
Tony Bowden 18:56 on 26 Jun 2005

Re: Order of before_delete trigger in docs
Marius Feraru 01:34 on 27 Jun 2005

Re: Order of before_delete trigger in docs
Bill Moseley 07:22 on 27 Jun 2005

Re: Order of before_delete trigger in docs
Tony Bowden 07:35 on 27 Jun 2005

Re: Order of before_delete trigger in docs
Marius Feraru 07:44 on 27 Jun 2005

Re: Order of before_delete trigger in docs
Tony Bowden 07:47 on 27 Jun 2005

Re: Order of before_delete trigger in docs
Marius Feraru 07:54 on 27 Jun 2005

Re: Order of before_delete trigger in docs
Marius Feraru 12:35 on 27 Jun 2005

Re: Order of before_delete trigger in docs
William Ross 14:03 on 27 Jun 2005

Re: Order of before_delete trigger in docs
Bill Moseley 15:11 on 27 Jun 2005

Re: Order of before_delete trigger in docs
Charles Bailey 16:23 on 27 Jun 2005

Re: Order of before_delete trigger in docs
William Ross 19:37 on 27 Jun 2005

Re: Order of before_delete trigger in docs
Tony Bowden 19:54 on 27 Jun 2005

Re: Order of before_delete trigger in docs
William Ross 20:52 on 27 Jun 2005

Generated at 16:37 on 28 Jul 2005 by mariachi v0.52