[Jifty-commit] r2444 - in Jifty-DBI/trunk: lib/Jifty/DBI

jifty-commit at lists.jifty.org jifty-commit at lists.jifty.org
Sat Dec 30 15:42:04 EST 2006


Author: trs
Date: Sat Dec 30 15:42:03 2006
New Revision: 2444

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

Log:
 r18550 at zot:  tom | 2006-12-30 15:41:46 -0500
 Fix bug where validator_COLUMN subs weren't getting set as validators (thanks to Audrey for help)


Modified: Jifty-DBI/trunk/lib/Jifty/DBI/Column.pm
==============================================================================
--- Jifty-DBI/trunk/lib/Jifty/DBI/Column.pm	(original)
+++ Jifty-DBI/trunk/lib/Jifty/DBI/Column.pm	Sat Dec 30 15:42:03 2006
@@ -11,7 +11,6 @@
     name
     type
     default
-    validator
     readable writable
     length
     mandatory
@@ -27,6 +26,8 @@
     valid_values
     indexed
     autocompleted
+    _validator
+    record_class
     /;
 
 =head1 NAME
@@ -51,7 +52,22 @@
         return 1;
     }
     return 0;
+}
+
+sub validator {
+    my $self = shift;
+
+    if ( @_ ) {
+        $self->_validator( shift );
+    }
+    elsif ( not $self->_validator ) {
+        my $name = ( $self->aliased_as ? $self->aliased_as : $self->name );
+        my $can  = $self->record_class->can( "validate_" . $name );
+        
+        $self->_validator( $can ) if $can;
+    }
 
+    return $self->_validator;
 }
 
 # Aliases for compatibility with searchbuilder code

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	Sat Dec 30 15:42:03 2006
@@ -194,6 +194,11 @@
     my $column_name
         = ( $column->aliased_as ? $column->aliased_as : $column->name );
     my $package = ref($self) || $self;
+
+    # Make sure column has a record_class set as not all columns are added
+    # through add_column
+    $column->record_class( $package ) if not $column->record_class;
+
     no strict 'refs';    # We're going to be defining subs
 
     if ( not $self->can($column_name) ) {
@@ -274,9 +279,6 @@
         }
         *{ $package . "::" . "set_" . $column_name } = $subref;
     }
-
-    $column->validator( $self->can( "validate_" . $column_name ) )
-      if not $column->validator and $self->can("validate_" . $column_name );
 }
 
 
@@ -353,15 +355,17 @@
     my $self = shift;
     my $name = shift;
     $name = lc $name;
-
     
-
     $self->COLUMNS->{$name} = Jifty::DBI::Column->new()
-        unless exists $self->COLUMNS->{$name};
-	$self->_READABLE_COLS_CACHE(undef);
-$self->_WRITABLE_COLS_CACHE(undef);
-$self->_COLUMNS_CACHE(undef );
+    unless exists $self->COLUMNS->{$name};
+    $self->_READABLE_COLS_CACHE(undef);
+    $self->_WRITABLE_COLS_CACHE(undef);
+    $self->_COLUMNS_CACHE(undef );
     $self->COLUMNS->{$name}->name($name);
+
+    my $class = ref( $self ) || $self;
+    $self->COLUMNS->{$name}->record_class( $class );
+
     return $self->COLUMNS->{$name};
 }
 


More information about the Jifty-commit mailing list