[Jifty-commit] r1178 - in Jifty-DBI/trunk: . lib/Jifty/DBI
jifty-commit at lists.jifty.org
jifty-commit at lists.jifty.org
Tue Jun 6 16:48:20 EDT 2006
Author: alexmv
Date: Tue Jun 6 16:48:20 2006
New Revision: 1178
Modified:
Jifty-DBI/trunk/ (props changed)
Jifty-DBI/trunk/lib/Jifty/DBI/Record.pm
Jifty-DBI/trunk/t/02-column_constraints.t
Log:
r13566 at zoq-fot-pik: chmrr | 2006-06-06 16:48:12 -0400
* Enforce mandatory things at a Jifty::DBI layer
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 Tue Jun 6 16:48:20 2006
@@ -883,6 +883,11 @@
if (not defined $attribs{$column->name} and defined $column->default and not ref $column->default) {
$attribs{$column->name} = $column->default;
}
+ if (not defined $attribs{$column->name} and $column->mandatory and $column->type ne "serial" ) {
+ # Enforce "mandatory"
+ warn "Did not supply value for mandatory column ".$column->name;
+ return ( 0 );
+ }
}
my $ret = $self->_handle->insert( $self->table, %attribs );
Modified: Jifty-DBI/trunk/t/02-column_constraints.t
==============================================================================
--- Jifty-DBI/trunk/t/02-column_constraints.t (original)
+++ Jifty-DBI/trunk/t/02-column_constraints.t Tue Jun 6 16:48:20 2006
@@ -31,7 +31,7 @@
isa_ok($ret,'DBI::st', "Inserted the schema. got a statement handle back");
my $emp = TestApp::Employee->new($handle);
- my $e_id = $emp->create( Name => 'RUZ', employee_num => '123' );
+ my $e_id = $emp->create( name => 'RUZ', employee_num => '123' );
ok($e_id, "Got an id for the new employee");
# Test 'is mandatory'
@@ -39,9 +39,9 @@
ok(!$e_id, "Did not get an id for second new employee, good");
# Test 'is distinct'
- $e_id = $emp->create( Name => 'Foo', employee_num => '456' );
+ $e_id = $emp->create( name => 'Foo', employee_num => '456' );
ok($e_id, "Was able to create a second record successfully");
- my $e_id2 = $emp->create( Name => 'Bar', employee_num => '123' );
+ my $e_id2 = $emp->create( name => 'Bar', employee_num => '123' );
ok(!$e_id2, "is_distinct prevents us from creating another record");
my $obj = TestApp::Employee->new($handle);
$obj->load( $e_id );
More information about the Jifty-commit
mailing list