[Jifty-commit] r3116 - Jifty-DBI/trunk/lib/Jifty/DBI

jifty-commit at lists.jifty.org jifty-commit at lists.jifty.org
Wed Apr 11 11:47:31 EDT 2007


Author: evdb
Date: Wed Apr 11 11:47:27 2007
New Revision: 3116

Modified:
   Jifty-DBI/trunk/lib/Jifty/DBI/Record.pm

Log:
Added sample code to POD for 'before_create' and 'after_create' to make it easier for users to implement by copy and pasting.


Modified: Jifty-DBI/trunk/lib/Jifty/DBI/Record.pm
==============================================================================
--- Jifty-DBI/trunk/lib/Jifty/DBI/Record.pm	(original)
+++ Jifty-DBI/trunk/lib/Jifty/DBI/Record.pm	Wed Apr 11 11:47:27 2007
@@ -1019,6 +1019,17 @@
 
 =item before_create
 
+  sub before_create {
+      my $self = shift;
+      my $args = shift;
+
+      # Do any checks and changes on $args here.
+      $args->{first_name} = ucfirst $args->{first_name};
+
+      return;      # false return vallue will abort the create
+      return 1;    # true return value will allow create to continue
+  }
+
 This method is called before trying to create our row in the
 database. It's handed a reference to your paramhash. (That means it
 can modify your parameters on the fly).  C<before_create> returns a
@@ -1026,6 +1037,18 @@
 
 =item after_create
 
+  sub after_create {
+      my $self                    = shift;
+      my $insert_return_value_ref = shift;
+
+      return unless $$insert_return_value_ref;    # bail if insert failed
+      $self->load($$insert_return_value_ref);     # load ourselves from db
+
+      # Do whatever needs to be done here
+
+      return; # return value is ignored
+  }
+
 This method is called after attempting to insert the record into the
 database. It gets handed a reference to the return value of the
 insert. That'll either be a true value or a L<Class::ReturnValue>


More information about the Jifty-commit mailing list