[Bast-commits] r3414 - in branches/DBIx-Class-current: . lib/DBIx/Class t

matthewt at dev.catalyst.perl.org matthewt at dev.catalyst.perl.org
Tue May 29 02:07:46 GMT 2007


Author: matthewt
Date: 2007-05-29 02:07:45 +0100 (Tue, 29 May 2007)
New Revision: 3414

Modified:
   branches/DBIx-Class-current/
   branches/DBIx-Class-current/lib/DBIx/Class/ResultSet.pm
   branches/DBIx-Class-current/t/101populate_rs.t
Log:
 r51615 at cain (orig r3317):  jnapiorkowski | 2007-05-15 17:59:59 +0000
 Passes all the tests but..
  -- Had to change the test to make each row declare the same columns (no autocreate for autoPKs)
  -- Right now inner related resultsets call popular in array context.  Needs to be fixed



Property changes on: branches/DBIx-Class-current
___________________________________________________________________
Name: svk:merge
   - 168d5346-440b-0410-b799-f706be625ff1:/DBIx-Class-current:2207
462d4d0c-b505-0410-bf8e-ce8f877b3390:/local/bast/DBIx-Class:3159
78d5d833-3a7e-474d-aed6-cfba645156b5:/local/DBIx-Class.bulk_create:29204
78d5d833-3a7e-474d-aed6-cfba645156b5:/local/DBIx-Class.current:29201
78d5d833-3a7e-474d-aed6-cfba645156b5:/local/DBIx-Class.oracle8:29250
bd8105ee-0ff8-0310-8827-fb3f25b6796d:/branches/DBIx-Class-C3:318
bd8105ee-0ff8-0310-8827-fb3f25b6796d:/branches/DBIx-Class-joins:173
bd8105ee-0ff8-0310-8827-fb3f25b6796d:/branches/DBIx-Class-resultset:570
bd8105ee-0ff8-0310-8827-fb3f25b6796d:/branches/DBIx-Class/bulk_create:3314
bd8105ee-0ff8-0310-8827-fb3f25b6796d:/branches/DBIx-Class/collapse_result_rewrite:3292
bd8105ee-0ff8-0310-8827-fb3f25b6796d:/branches/DBIx-Class/column_info_from_storage:2596
bd8105ee-0ff8-0310-8827-fb3f25b6796d:/branches/DBIx-Class/datetime:1716
bd8105ee-0ff8-0310-8827-fb3f25b6796d:/branches/DBIx-Class/find_compat:1855
bd8105ee-0ff8-0310-8827-fb3f25b6796d:/branches/DBIx-Class/find_unique_query_fixes:2142
bd8105ee-0ff8-0310-8827-fb3f25b6796d:/branches/DBIx-Class/inflate:1988
bd8105ee-0ff8-0310-8827-fb3f25b6796d:/branches/DBIx-Class/load_namespaces:2725
bd8105ee-0ff8-0310-8827-fb3f25b6796d:/branches/DBIx-Class/many_to_many:2025
bd8105ee-0ff8-0310-8827-fb3f25b6796d:/branches/DBIx-Class/param_bind:3015
bd8105ee-0ff8-0310-8827-fb3f25b6796d:/branches/DBIx-Class/re_refactor_bugfix:1944
bd8105ee-0ff8-0310-8827-fb3f25b6796d:/branches/DBIx-Class/reorganize_tests:1827
bd8105ee-0ff8-0310-8827-fb3f25b6796d:/branches/DBIx-Class/resultset-new-refactor:1766
bd8105ee-0ff8-0310-8827-fb3f25b6796d:/branches/DBIx-Class/resultset_2_electric_boogaloo:2175
bd8105ee-0ff8-0310-8827-fb3f25b6796d:/branches/DBIx-Class/resultset_cleanup:2102
bd8105ee-0ff8-0310-8827-fb3f25b6796d:/branches/DBIx-Class/source-handle:2975
bd8105ee-0ff8-0310-8827-fb3f25b6796d:/branches/DBIx-Class/sqlt_tests_refactor:2043
bd8105ee-0ff8-0310-8827-fb3f25b6796d:/branches/DBIx-Class/storage_exceptions:2617
bd8105ee-0ff8-0310-8827-fb3f25b6796d:/branches/DBIx-Class/versioning:2930
bd8105ee-0ff8-0310-8827-fb3f25b6796d:/trunk/DBIx-Class:3355
   + 168d5346-440b-0410-b799-f706be625ff1:/DBIx-Class-current:2207
462d4d0c-b505-0410-bf8e-ce8f877b3390:/local/bast/DBIx-Class:3159
78d5d833-3a7e-474d-aed6-cfba645156b5:/local/DBIx-Class.bulk_create:29204
78d5d833-3a7e-474d-aed6-cfba645156b5:/local/DBIx-Class.current:29201
78d5d833-3a7e-474d-aed6-cfba645156b5:/local/DBIx-Class.oracle8:29250
bd8105ee-0ff8-0310-8827-fb3f25b6796d:/branches/DBIx-Class-C3:318
bd8105ee-0ff8-0310-8827-fb3f25b6796d:/branches/DBIx-Class-joins:173
bd8105ee-0ff8-0310-8827-fb3f25b6796d:/branches/DBIx-Class-resultset:570
bd8105ee-0ff8-0310-8827-fb3f25b6796d:/branches/DBIx-Class/bulk_create:3317
bd8105ee-0ff8-0310-8827-fb3f25b6796d:/branches/DBIx-Class/collapse_result_rewrite:3292
bd8105ee-0ff8-0310-8827-fb3f25b6796d:/branches/DBIx-Class/column_info_from_storage:2596
bd8105ee-0ff8-0310-8827-fb3f25b6796d:/branches/DBIx-Class/datetime:1716
bd8105ee-0ff8-0310-8827-fb3f25b6796d:/branches/DBIx-Class/find_compat:1855
bd8105ee-0ff8-0310-8827-fb3f25b6796d:/branches/DBIx-Class/find_unique_query_fixes:2142
bd8105ee-0ff8-0310-8827-fb3f25b6796d:/branches/DBIx-Class/inflate:1988
bd8105ee-0ff8-0310-8827-fb3f25b6796d:/branches/DBIx-Class/load_namespaces:2725
bd8105ee-0ff8-0310-8827-fb3f25b6796d:/branches/DBIx-Class/many_to_many:2025
bd8105ee-0ff8-0310-8827-fb3f25b6796d:/branches/DBIx-Class/param_bind:3015
bd8105ee-0ff8-0310-8827-fb3f25b6796d:/branches/DBIx-Class/re_refactor_bugfix:1944
bd8105ee-0ff8-0310-8827-fb3f25b6796d:/branches/DBIx-Class/reorganize_tests:1827
bd8105ee-0ff8-0310-8827-fb3f25b6796d:/branches/DBIx-Class/resultset-new-refactor:1766
bd8105ee-0ff8-0310-8827-fb3f25b6796d:/branches/DBIx-Class/resultset_2_electric_boogaloo:2175
bd8105ee-0ff8-0310-8827-fb3f25b6796d:/branches/DBIx-Class/resultset_cleanup:2102
bd8105ee-0ff8-0310-8827-fb3f25b6796d:/branches/DBIx-Class/source-handle:2975
bd8105ee-0ff8-0310-8827-fb3f25b6796d:/branches/DBIx-Class/sqlt_tests_refactor:2043
bd8105ee-0ff8-0310-8827-fb3f25b6796d:/branches/DBIx-Class/storage_exceptions:2617
bd8105ee-0ff8-0310-8827-fb3f25b6796d:/branches/DBIx-Class/versioning:2930
bd8105ee-0ff8-0310-8827-fb3f25b6796d:/trunk/DBIx-Class:3355

Modified: branches/DBIx-Class-current/lib/DBIx/Class/ResultSet.pm
===================================================================
--- branches/DBIx-Class-current/lib/DBIx/Class/ResultSet.pm	2007-05-29 01:07:40 UTC (rev 3413)
+++ branches/DBIx-Class-current/lib/DBIx/Class/ResultSet.pm	2007-05-29 01:07:45 UTC (rev 3414)
@@ -1280,7 +1280,7 @@
 use Data::Dump qw/dump/;
 
 sub populate {
-  my ($self, $data) = @_;
+  my ($self, $data) = @_;  #warn dump $self->result_source->primary_columns;
   
   if(defined wantarray) {
     my @created;
@@ -1292,15 +1292,39 @@
   else
   {
     my ($first, @rest) = @$data;
-    my @names = keys %$first;
 	
-	warn dump keys %$_ for @$data;
+	## We assume for now that the first item is required to name all the columns
+	## and relationships similarly to how schema->populate requires a first item
+	## of all the column names.
 	
-	#@$data = map { my %unit = %$_; warn dump @unit{qw/cds artistid/}; warn dump %unit; } @$data;
+    my @names = grep { !$self->result_source->has_relationship($_) } keys %$first;
 	
-	die "Void mode not supported yet :)";
+    $self->result_source->storage->insert_bulk(
+		$self->result_source, 
+		\@names, 
+		[map { [ map {defined $_ ? $_ : $self->throw_exception("Undefined value for column!")} @$_{@names} ] } @$data]
+	);
 	
-    #$self->result_source->storage->insert_bulk($self->result_source, \@names, $data);
+	## Again we assume the first row has to define all the related resultsets
+	my @rels = grep { $self->result_source->has_relationship($_) } keys %$first;
+	my @pks = $self->result_source->primary_columns;
+	
+	## Must have PKs to use this!!!
+	
+	foreach my $item (@$data)
+	{
+		## First we need to get a result for each
+		## We need to call populate for each relationship.
+		
+		foreach my $rel (@rels)
+		{
+			my $result = $self->find(map {{$_=>$item->{$_}} } @pks);
+			
+			my @discard = $result->$rel->populate($item->{$rel});
+			#$result->$rel->populate($item->{$rel});
+		}
+	}
+	
   }
 }
 

Modified: branches/DBIx-Class-current/t/101populate_rs.t
===================================================================
--- branches/DBIx-Class-current/t/101populate_rs.t	2007-05-29 01:07:40 UTC (rev 3413)
+++ branches/DBIx-Class-current/t/101populate_rs.t	2007-05-29 01:07:45 UTC (rev 3414)
@@ -5,14 +5,14 @@
 use lib qw(t/lib);
 use DBICTest;
 
-plan tests => 18;
+plan tests => 25;
 
 my $schema = DBICTest->init_schema();
 my $rs = $schema->resultset('Artist');
 
 RETURN_RESULTSETS: {
 
-	my ($crap, $girl) = $rs->populate( [
+	my ($crap, $girl, $damn) = $rs->populate( [
 	  { artistid => 4, name => 'Manufactured Crap', cds => [ 
 		  { title => 'My First CD', year => 2006 },
 		  { title => 'Yet More Tweeny-Pop crap', year => 2007 },
@@ -25,12 +25,13 @@
 
 		]
 	  },
-	  { name => 'Like I Give a Damn' }
+	  { artistid=>6, name => 'Like I Give a Damn' }
 
 	] );
 	
 	isa_ok( $crap, 'DBICTest::Artist', "Got 'Artist'");
-	isa_ok( $girl, 'DBICTest::Artist', "Got 'Artist'");
+	isa_ok( $damn, 'DBICTest::Artist', "Got 'Artist'");
+	isa_ok( $girl, 'DBICTest::Artist', "Got 'Artist'");	
 	
 	ok( $crap->name eq 'Manufactured Crap', "Got Correct name for result object");
 	ok( $girl->name eq 'Angsty-Whiny Girl', "Got Correct name for result object");
@@ -44,56 +45,57 @@
 RETURN_VOID: {
 
 	$rs->populate( [
-	  { artistid => 4, name => 'Manufactured Crap', cds => [ 
-		  { title => 'My First CD', year => 2006 },
-		  { title => 'Yet More Tweeny-Pop crap', year => 2007 },
+	  { artistid => 7, name => 'Manufactured CrapB', cds => [ 
+		  { title => 'My First CDB', year => 2006 },
+		  { title => 'Yet More Tweeny-Pop crapB', year => 2007 },
 		] 
 	  },
-	  { artistid => 5, name => 'Angsty-Whiny Girl', cds => [
-		  { title => 'My parents sold me to a record company' ,year => 2005 },
-		  { title => 'Why Am I So Ugly?', year => 2006 },
-		  { title => 'I Got Surgery and am now Popular', year => 2007 }
+	  { artistid => 8, name => 'Angsty-Whiny GirlB', cds => [
+		  { title => 'My parents sold me to a record companyB' ,year => 2005 },
+		  { title => 'Why Am I So Ugly?B', year => 2006 },
+		  { title => 'I Got Surgery and am now PopularB', year => 2007 }
 
 		]
 	  },
-	  { name => 'Like I Give a Damn' }
+	  {artistid=>9,  name => 'XXXX' }
 
 	] );
+	
+	my $artist = $rs->find(7);
 
-	my $artist = $rs->find(4);
-
 	ok($artist, 'Found artist');
-	is($artist->name, 'Manufactured Crap');
+	is($artist->name, 'Manufactured CrapB');
 	is($artist->cds->count, 2, 'Has CDs');
 
 	my @cds = $artist->cds;
 
-	is($cds[0]->title, 'My First CD', 'A CD');
+	is($cds[0]->title, 'My First CDB', 'A CD');
 	is($cds[0]->year,  2006, 'Published in 2006');
 
-	is($cds[1]->title, 'Yet More Tweeny-Pop crap', 'Another crap CD');
+	is($cds[1]->title, 'Yet More Tweeny-Pop crapB', 'Another crap CD');
 	is($cds[1]->year,  2007, 'Published in 2007');
 
-	$artist = $rs->find(5);
+	$artist = $rs->find(8);
 	ok($artist, 'Found artist');
-	is($artist->name, 'Angsty-Whiny Girl');
+	is($artist->name, 'Angsty-Whiny GirlB');
 	is($artist->cds->count, 3, 'Has CDs');
 
 	@cds = $artist->cds;
 
 
-	is($cds[0]->title, 'My parents sold me to a record company', 'A CD');
+	is($cds[0]->title, 'My parents sold me to a record companyB', 'A CD');
 	is($cds[0]->year,  2005, 'Published in 2005');
 
-	is($cds[1]->title, 'Why Am I So Ugly?', 'A Coaster');
+	is($cds[1]->title, 'Why Am I So Ugly?B', 'A Coaster');
 	is($cds[1]->year,  2006, 'Published in 2006');
 
-	is($cds[2]->title, 'I Got Surgery and am now Popular', 'Selling un-attainable dreams');
+	is($cds[2]->title, 'I Got Surgery and am now PopularB', 'Selling un-attainable dreams');
 	is($cds[2]->year,  2007, 'Published in 2007');
 
-	$artist = $rs->search({name => 'Like I Give A Damn'})->single;
-	ok($artist);
+	$artist = $rs->search({name => 'XXXX'})->single;
+	ok($artist, "Got Expected Artist Result");
 
 	is($artist->cds->count, 0, 'No CDs');
+
 }
 




More information about the Bast-commits mailing list