[Jifty-commit] r5227 - in Jifty-DBI/trunk: . lib/Jifty/DBI lib/Jifty/DBI/Filter
Jifty commits
jifty-commit at lists.jifty.org
Mon Mar 17 14:39:05 EDT 2008
Author: alexmv
Date: Mon Mar 17 14:39:05 2008
New Revision: 5227
Modified:
Jifty-DBI/trunk/ (props changed)
Jifty-DBI/trunk/lib/Jifty/DBI/Filter/Boolean.pm
Jifty-DBI/trunk/lib/Jifty/DBI/Record.pm
Jifty-DBI/trunk/lib/Jifty/DBI/Schema.pm
Jifty-DBI/trunk/t/06filter_boolean.t
Log:
r28569 at kohr-ah: chmrr | 2008-03-17 14:38:49 -0400
* Fixes for NULL boolean columns
* Booleans get canonicalizers, so perl-level gets canonical values,
not just the DB.
* Canonicalization fixes
Modified: Jifty-DBI/trunk/lib/Jifty/DBI/Filter/Boolean.pm
==============================================================================
--- Jifty-DBI/trunk/lib/Jifty/DBI/Filter/Boolean.pm (original)
+++ Jifty-DBI/trunk/lib/Jifty/DBI/Filter/Boolean.pm Mon Mar 17 14:39:05 2008
@@ -77,7 +77,8 @@
my $self = shift;
my $value_ref = $self->value_ref;
- return unless defined $$value_ref;
+ return unless defined $$value_ref or $self->column->mandatory;
+ return if uc $$value_ref eq "NULL" and not $self->column->mandatory;
if ($self->_is_true($$value_ref)) {
$$value_ref = $self->handle->canonical_true;
@@ -98,4 +99,3 @@
=cut
1;
-
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 Mon Mar 17 14:39:05 2008
@@ -1377,7 +1377,6 @@
and $column->mandatory
and $column->type ne "serial" )
{
-
# Enforce "mandatory"
Carp::carp "Did not supply value for mandatory column "
. $column->name;
@@ -1634,7 +1633,8 @@
my ( $ret, $value_ref ) = $self->_run_callback(
name => "canonicalize_" . $args{'column'},
- args => $args{'value'}
+ args => $args{'value'},
+ short_circuit => 0,
);
return unless defined $ret;
return (
@@ -1656,6 +1656,8 @@
my $method = "canonicalize_$key";
if ( $self->can($method) ) {
return 1;
+ } elsif ( Class::Trigger::__fetch_all_triggers($self, $method) ) {
+ return 1;
} else {
return undef;
}
@@ -1697,7 +1699,10 @@
sub has_validator_for_column {
my $self = shift;
my $key = shift;
- if ( $self->can( "validate_" . $key ) ) {
+ my $method = "validate_$key";
+ if ( $self->can( $method ) ) {
+ return 1;
+ } elsif ( Class::Trigger::__fetch_all_triggers($self, $method) ) {
return 1;
} else {
return undef;
@@ -1709,6 +1714,7 @@
my %args = (
name => undef,
args => undef,
+ short_circuit => 1,
@_
);
@@ -1718,7 +1724,7 @@
if ( my $func = $self->can($method) ) {
@results = $func->( $self, $args{args} );
return ( wantarray ? ( undef, [ [@results] ] ) : undef )
- unless $results[0];
+ if $args{short_circuit} and not $results[0];
}
$ret = $self->call_trigger( $args{'name'} => $args{args} );
return (
Modified: Jifty-DBI/trunk/lib/Jifty/DBI/Schema.pm
==============================================================================
--- Jifty-DBI/trunk/lib/Jifty/DBI/Schema.pm (original)
+++ Jifty-DBI/trunk/lib/Jifty/DBI/Schema.pm Mon Mar 17 14:39:05 2008
@@ -405,14 +405,22 @@
__PACKAGE__->register_types(
boolean => sub {
+ encode_on_select is 1,
+ type is 'boolean',
+ filters are qw(Jifty::DBI::Filter::Boolean),
+ default is 'false',
_init_handler is sub {
my ($column, $from) = @_;
- $column->encode_on_select(1);
- $column->type('boolean');
+ no strict 'refs';
+ Class::Trigger::add_trigger($from, name => "canonicalize_" . $column->name, callback => sub {
+ my ($self,$value) = @_;
+ $self->_apply_output_filters(
+ column => $column,
+ value_ref => \$value,
+ );
+ return $value;
+ });
},
- type is 'boolean',
- filters are qw(Jifty::DBI::Filter::Boolean),
- default is 0,
},
);
Modified: Jifty-DBI/trunk/t/06filter_boolean.t
==============================================================================
--- Jifty-DBI/trunk/t/06filter_boolean.t (original)
+++ Jifty-DBI/trunk/t/06filter_boolean.t Mon Mar 17 14:39:05 2008
@@ -6,7 +6,7 @@
BEGIN { require "t/utils.pl" }
our (@available_drivers);
-use constant TESTS_PER_DRIVER => 130;
+use constant TESTS_PER_DRIVER => 136;
my $total = scalar(@available_drivers) * TESTS_PER_DRIVER;
plan tests => $total;
@@ -98,6 +98,20 @@
}
}
+ # Test undef for boolean columns marked mandatory
+ my $rec = TestApp::User->new( handle => $handle );
+ my ($id) = $rec->create();
+ ok($id, 'created record');
+ ok($rec->load($id), 'loaded record');
+ is($rec->id, $id, 'record id matches');
+ is($rec->other_data, 0, 'default mandatory column is false, not undef');
+
+ $rec->set_other_data(1);
+ is($rec->other_data, 1, 'mandatory column is now true');
+
+ $rec->set_other_data(undef);
+ is($rec->other_data, 0, 'mandatory column set to undef is now false, not undef');
+
cleanup_schema('TestApp', $handle);
disconnect_handle($handle);
}
@@ -111,7 +125,8 @@
<<EOF;
CREATE table users (
id integer primary key,
- my_data boolean
+ my_data boolean,
+ other_data boolean not null
)
EOF
@@ -122,7 +137,8 @@
<<EOF;
CREATE TEMPORARY table users (
id integer auto_increment primary key,
- my_data boolean
+ my_data boolean,
+ other_data boolean not null
)
EOF
@@ -133,7 +149,8 @@
<<EOF;
CREATE TEMPORARY table users (
id serial primary key,
- my_data boolean
+ my_data boolean,
+ other_data boolean not null
)
EOF
@@ -145,6 +162,10 @@
use Jifty::DBI::Record schema {
column my_data =>
is boolean;
+
+ column other_data =>
+ is boolean,
+ is mandatory;
}
}
More information about the Jifty-commit
mailing list