[Jifty-commit] r3960 - in Jifty-DBI/trunk: lib/Jifty/DBI/Record

jifty-commit at lists.jifty.org jifty-commit at lists.jifty.org
Fri Aug 24 08:30:38 EDT 2007


Author: sterling
Date: Fri Aug 24 08:30:36 2007
New Revision: 3960

Modified:
   Jifty-DBI/trunk/   (props changed)
   Jifty-DBI/trunk/lib/Jifty/DBI/Record/Plugin.pm

Log:
 r8874 at dynpc145:  andrew | 2007-08-22 12:03:07 -0500
 Updated documentation to discuss the register_triggers_late() method.


Modified: Jifty-DBI/trunk/lib/Jifty/DBI/Record/Plugin.pm
==============================================================================
--- Jifty-DBI/trunk/lib/Jifty/DBI/Record/Plugin.pm	(original)
+++ Jifty-DBI/trunk/lib/Jifty/DBI/Record/Plugin.pm	Fri Aug 24 08:30:36 2007
@@ -82,6 +82,32 @@
 
 See L<Jifty::DBI::Class::Trigger>.
 
+=head3 register_triggers_late
+
+In cases where a column may be added to the schema after L</register_triggers> has been called, you may want to implement the C<register_triggers_late> method as well. At this time, this primarily used by the database-backed models provided by Jifty. (As of this writing, part of the virtual-models branch only available from Subversion, but planned for merge into trunk for release.)
+
+This method works exactly the same as C<register_triggers>, except that it will be passed the name of the column that has been added to the model schema.
+
+  sub register_triggers_late {
+      my $self   = shift;
+      my $column = shift;
+
+      return unless $column ne 'updated_on';
+
+      $self->add_trigger( 
+          name      => 'after_set_'.$column, 
+          callback  => \&touch_update_time,
+          abortable => 1,
+      );
+  }
+
+  sub touch_update_time {
+      my $self = shift;
+      $self->set_updated_on(DateTime->now);
+  }
+
+See L<Jifty::DBI::Class::Trigger>.
+
 =head2 MODELS USING MIXINS
 
 To use your model plugin, just use the mixins you want to get columns from. You should still include a schema definition, even if it's empty:


More information about the Jifty-commit mailing list