[Bast-commits] r6123 - in
DBIx-Class-ResultSet-RecursiveUpdate/1.000/trunk:
lib/DBIx/Class/ResultSet t t/lib t/lib/DBSchema/Result t/var
zby at dev.catalyst.perl.org
zby at dev.catalyst.perl.org
Mon May 4 22:30:59 GMT 2009
Author: zby
Date: 2009-05-04 22:30:59 +0000 (Mon, 04 May 2009)
New Revision: 6123
Added:
DBIx-Class-ResultSet-RecursiveUpdate/1.000/trunk/t/lib/DBSchema/Result/Address.pm
Modified:
DBIx-Class-ResultSet-RecursiveUpdate/1.000/trunk/lib/DBIx/Class/ResultSet/RecursiveUpdate.pm
DBIx-Class-ResultSet-RecursiveUpdate/1.000/trunk/t/lib/DBSchema.pm
DBIx-Class-ResultSet-RecursiveUpdate/1.000/trunk/t/lib/DBSchema/Result/User.pm
DBIx-Class-ResultSet-RecursiveUpdate/1.000/trunk/t/lib/RunTests.pm
DBIx-Class-ResultSet-RecursiveUpdate/1.000/trunk/t/sqlite.t
DBIx-Class-ResultSet-RecursiveUpdate/1.000/trunk/t/var/dvdzbr.db
Log:
might_have with non pk fk
Modified: DBIx-Class-ResultSet-RecursiveUpdate/1.000/trunk/lib/DBIx/Class/ResultSet/RecursiveUpdate.pm
===================================================================
--- DBIx-Class-ResultSet-RecursiveUpdate/1.000/trunk/lib/DBIx/Class/ResultSet/RecursiveUpdate.pm 2009-05-04 21:07:43 UTC (rev 6122)
+++ DBIx-Class-ResultSet-RecursiveUpdate/1.000/trunk/lib/DBIx/Class/ResultSet/RecursiveUpdate.pm 2009-05-04 22:30:59 UTC (rev 6123)
@@ -30,8 +30,6 @@
if ( blessed($updates) && $updates->isa('DBIx::Class::Row') ) {
return $updates;
}
-
-
# direct column accessors
my %columns;
@@ -76,7 +74,7 @@
}
$object ||= $self->new( {} );
-# first update columns and other accessors - so that later related records can be found
+ # first update columns and other accessors - so that later related records can be found
for my $name ( keys %columns ) {
$object->$name( $updates->{$name} );
}
@@ -85,7 +83,6 @@
_update_relation( $self, $name, $updates, $object, $info );
}
# $self->_delete_empty_auto_increment($object);
-
# don't allow insert to recurse to related objects - we do the recursion ourselves
# $object->{_rel_in_storage} = 1;
$object->update_or_insert;
@@ -151,8 +148,18 @@
else {
my $sub_updates = $updates->{$name};
$sub_updates = { %$sub_updates, %$resolved } if $resolved && ref( $sub_updates ) eq 'HASH';
- my $sub_object =
- recursive_update( resultset => $related_result, updates => $sub_updates );
+ my $sub_object;
+ if( $info->{attrs}{accessor} eq 'single' && defined $object->$name ){
+ $sub_object = recursive_update(
+ resultset => $related_result,
+ updates => $sub_updates,
+ object => $object->$name
+ );
+ }
+ else{
+ $sub_object =
+ recursive_update( resultset => $related_result, updates => $sub_updates );
+ }
$object->set_from_related( $name, $sub_object );
}
}
Added: DBIx-Class-ResultSet-RecursiveUpdate/1.000/trunk/t/lib/DBSchema/Result/Address.pm
===================================================================
--- DBIx-Class-ResultSet-RecursiveUpdate/1.000/trunk/t/lib/DBSchema/Result/Address.pm (rev 0)
+++ DBIx-Class-ResultSet-RecursiveUpdate/1.000/trunk/t/lib/DBSchema/Result/Address.pm 2009-05-04 22:30:59 UTC (rev 6123)
@@ -0,0 +1,32 @@
+package DBSchema::Result::Address;
+
+use strict;
+use warnings;
+
+use base 'DBIx::Class';
+
+__PACKAGE__->load_components("Core");
+__PACKAGE__->table("address");
+__PACKAGE__->add_columns(
+ "address_id",
+ { data_type => "INTEGER", is_auto_increment => 1,
+ is_nullable => 0 },
+ "user_id",
+ { data_type => "INTEGER", is_nullable => 0 },
+ "street",
+ { data_type => "VARCHAR", is_nullable => 0, size => 32 },
+ "city",
+ { data_type => "VARCHAR", is_nullable => 0, size => 32 },
+ "state",
+ { data_type => "VARCHAR", is_nullable => 0, size => 32 },
+);
+__PACKAGE__->set_primary_key("address_id");
+
+__PACKAGE__->belongs_to(
+ 'user',
+ 'DBSchema::Result::User',
+ 'user_id',
+);
+
+
+1;
Modified: DBIx-Class-ResultSet-RecursiveUpdate/1.000/trunk/t/lib/DBSchema/Result/User.pm
===================================================================
--- DBIx-Class-ResultSet-RecursiveUpdate/1.000/trunk/t/lib/DBSchema/Result/User.pm 2009-05-04 21:07:43 UTC (rev 6122)
+++ DBIx-Class-ResultSet-RecursiveUpdate/1.000/trunk/t/lib/DBSchema/Result/User.pm 2009-05-04 22:30:59 UTC (rev 6123)
@@ -38,5 +38,11 @@
);
__PACKAGE__->many_to_many('roles', 'user_roles' => 'role');
+__PACKAGE__->might_have(
+ "address",
+ "DBSchema::Result::Address",
+ { 'foreign.user_id' => 'self.id' }
+);
+
1;
Modified: DBIx-Class-ResultSet-RecursiveUpdate/1.000/trunk/t/lib/DBSchema.pm
===================================================================
--- DBIx-Class-ResultSet-RecursiveUpdate/1.000/trunk/t/lib/DBSchema.pm 2009-05-04 21:07:43 UTC (rev 6122)
+++ DBIx-Class-ResultSet-RecursiveUpdate/1.000/trunk/t/lib/DBSchema.pm 2009-05-04 22:30:59 UTC (rev 6123)
@@ -15,7 +15,7 @@
$dsn ||= 'dbi:SQLite:dbname=t/var/dvdzbr.db';
warn "testing $dsn";
my $schema = __PACKAGE__->connect( $dsn, $user, $pass, {} );
- $schema->deploy({ });
+ $schema->deploy({ add_drop_table => 1, });
$schema->populate('User', [
[ qw/username name password / ],
[ 'jgda', 'Jonas Alves', ''],
Modified: DBIx-Class-ResultSet-RecursiveUpdate/1.000/trunk/t/lib/RunTests.pm
===================================================================
--- DBIx-Class-ResultSet-RecursiveUpdate/1.000/trunk/t/lib/RunTests.pm 2009-05-04 21:07:43 UTC (rev 6122)
+++ DBIx-Class-ResultSet-RecursiveUpdate/1.000/trunk/t/lib/RunTests.pm 2009-05-04 22:30:59 UTC (rev 6123)
@@ -9,7 +9,7 @@
sub run_tests{
my $schema = shift;
- plan tests => 28;
+ plan tests => 29;
my $dvd_rs = $schema->resultset( 'Dvd' );
my $user_rs = $schema->resultset( 'User' );
@@ -133,6 +133,20 @@
is( scalar @tags, 2, 'Tags in has_many related record saved' );
ok( $owned_dvds{'temp name 2'}, 'Second name in a has_many related record saved' );
+ $updates = {
+ id => $user->id,
+ address => {
+ street => "101 Main Street",
+ city => "Podunk",
+ state => "New York"
+ }
+ };
+ $user = $user_rs->recursive_update( $updates );
+ $user = $user_rs->recursive_update( $updates );
+ is( $schema->resultset( 'Address' )->search({ user_id => $user->id })->count, 1,
+ 'the right number of addresses' );
+
+
# $updates = {
# name => 'Test name 1',
# };
Modified: DBIx-Class-ResultSet-RecursiveUpdate/1.000/trunk/t/sqlite.t
===================================================================
--- DBIx-Class-ResultSet-RecursiveUpdate/1.000/trunk/t/sqlite.t 2009-05-04 21:07:43 UTC (rev 6122)
+++ DBIx-Class-ResultSet-RecursiveUpdate/1.000/trunk/t/sqlite.t 2009-05-04 22:30:59 UTC (rev 6123)
@@ -5,7 +5,7 @@
use RunTests;
use Test::More;
-unlink 't/var/dvdzbr.db';
+#unlink 't/var/dvdzbr.db';
my $schema = DBSchema::get_test_schema();
run_tests( $schema );
Modified: DBIx-Class-ResultSet-RecursiveUpdate/1.000/trunk/t/var/dvdzbr.db
===================================================================
(Binary files differ)
More information about the Bast-commits
mailing list