Order of before_delete trigger in docs

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

From: Bill Moseley
Subject: Order of before_delete trigger in docs
Date: 17:32 on 26 Jun 2005
The docs for the delete method say:

       The "before_delete" trigger is when an object instance is about to be
       deleted. It is invoked before any cascaded deletes.

Perhaps I'm not understanding the wording, but it seems like the
trigger is called after the cascaded deletes:

    DB::Role->has_many( roles => [ 'DB::PersonRole' => 'role' ] );

    DB::Role->add_trigger( before_delete => sub { warn "Role before_delete\n" });
    DB::PersonRole->add_trigger( before_delete => sub { warn "PersonRole before_delete\n" });

    my $role = DB::Role->find_or_create( { name => 'Admin' } );
    my $person1 = DB::Person->create( { name => 'Person1' } );
    $person1->add_to_roles( { role => $role } );
    $role->delete;

results in:

    PersonRole before_delete
    Role before_delete


If that should be "after" then here's a patch against .999.


Oh, and I added a little about many-to-many as upon my first few
readings I wasn't clear what "do the right thing" was.  Add if you
like.  I was also not clear about the statement "will only delete the
relationship from the linking table".  $film->delete cascades so is
that suppose to be "will also delete"?


--- DBI.pm      2005-06-18 06:26:00.000000000 -0700
+++ DBI.pm.new  2005-06-26 10:27:41.396695224 -0700
@@ -1284,7 +1284,7 @@
                cdid   INTEGER   PRIMARY KEY,
                artist INTEGER, # references 'artist'
                title  VARCHAR(255),
-               year   CHAR(4),
+               year   CHAR(4)
        );
 
 =item I<Set up an application base class>
@@ -1541,8 +1541,8 @@
 returned from a search. Each object found will be deleted in turn,
 so cascading delete and other triggers will be honoured.
 
-The C<before_delete> trigger is when an object instance is about to be
-deleted. It is invoked before any cascaded deletes.  The C<after_delete>
+The C<before_delete> trigger is invoked when an object instance is about to be
+deleted. It is invoked after any cascaded deletes.  The C<after_delete>
 trigger is invoked after the record has been deleted from the database
 and just before the contents in memory are discarded.
 
@@ -2438,7 +2438,17 @@
        $film->add_to_actors({ actor => $actor });
 
 Similarly a cascading delete will also do the right thing as it will
-only delete the relationship from the linking table.
+also delete the relationship from the linking table.  For example:
+
+       $film->delete;
+
+will first delete all the relationships for $film in the Role table and
+then delete $film from the Film table.
+
+To delete just the relationships in the Role table related to $film leaving
+$film in the database:
+
+       Role->search({ film => $film })->delete_all;
 
 If the Role table were to contain extra information, such as the name
 of the character played, then you would usually need to skip these



        -- 
        Bill Moseley
moseley@xxxx.xxx

(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