Re: Order of before_delete trigger in docs

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

From: Marius Feraru
Subject: Re: Order of before_delete trigger in docs
Date: 07:54 on 27 Jun 2005
-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1


On Jun 27, at 00:22 (-0700), 'Bill Moseley' wrote:
> This started by trying to use a trigger to prevent a cascade delete

OFC. The usual drill ;-)

> with:
>
> DB::Role->add_trigger(before_delete => sub {
>    my $role = shift;
>    die "Can't delete Role ($role) -- In use by one or more Person records\n"
>        if DB::PersonRole->search( { role => $role } )->first;
> } );
>
> Which doesn't work when I use CDBI::Loader but does otherwise.

Hehe, too much magic stung you :)
Back on the more serious side, as I said, I had my trouble with the very 
same issue long time ago and I already told you my workaround. It's a 
pity CDBI has this flaw, but unluckily that's the way the Class::Trigger 
mixin works.

On the other hand, I would rewrite that trigger as following:

DB::Role->add_trigger(before_delete => sub {
   my $role = shift;
   $role->_croak("Can't delete Role ($role) -- In use by one or more Person records\n");
      if DB::PersonRole->search( { role => $role->id } );
);

$role->_croak
   to be more consistent with the way CDBI chooses to throw exceptions

$role->id
   avoid too much magic when it's all about adding just a few keystrokes,
   gaining some more speed in return

(dropped ->first)
   the iterator is more than enough for you to establish the right answer,
   nevermentioning what happens when there is no Person for that Role :)

- -- 
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-----

iD8DBQFCv7C+n0ZKufYp8iURAkXvAJ9e2ruFiXyfz+tVRSNWcjSar7T/eQCghbjJ
jYifjWR1r3JQrWyOVtniFF4=
=kKbV
-----END PGP SIGNATURE-----

(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