[Bast-commits] r3528 - in trunk/DBIx-Class: lib/DBIx lib/DBIx/Class t

jnapiorkowski at dev.catalyst.perl.org jnapiorkowski at dev.catalyst.perl.org
Mon Jun 25 23:55:25 GMT 2007


Author: jnapiorkowski
Date: 2007-06-25 23:55:24 +0100 (Mon, 25 Jun 2007)
New Revision: 3528

Modified:
   trunk/DBIx-Class/lib/DBIx/Class.pm
   trunk/DBIx-Class/lib/DBIx/Class/Schema.pm
   trunk/DBIx-Class/t/101populate_rs.t
Log:
Added multi-create object support to Schema->populate and created a test for this.  Also added my name to the contributors list so my wife believes me when I tell her what I'm working on in my offtime :)

Modified: trunk/DBIx-Class/lib/DBIx/Class/Schema.pm
===================================================================
--- trunk/DBIx-Class/lib/DBIx/Class/Schema.pm	2007-06-25 01:51:40 UTC (rev 3527)
+++ trunk/DBIx-Class/lib/DBIx/Class/Schema.pm	2007-06-25 22:55:24 UTC (rev 3528)
@@ -851,7 +851,15 @@
     }
     return @created;
   }
-  $self->storage->insert_bulk($self->source($name), \@names, $data);
+  my @results_to_create;
+  foreach my $datum (@$data) {
+    my %result_to_create;
+    foreach my $index (0..$#names) {
+      $result_to_create{$names[$index]} = $$datum[$index];
+    }
+    push @results_to_create, \%result_to_create;
+  }
+  $rs->populate(\@results_to_create);
 }
 
 =head2 exception_action

Modified: trunk/DBIx-Class/lib/DBIx/Class.pm
===================================================================
--- trunk/DBIx-Class/lib/DBIx/Class.pm	2007-06-25 01:51:40 UTC (rev 3527)
+++ trunk/DBIx-Class/lib/DBIx/Class.pm	2007-06-25 22:55:24 UTC (rev 3528)
@@ -222,6 +222,8 @@
 
 jguenther: Justin Guenther <jguenther at cpan.org>
 
+jnapiorkowski: John Napiorkowski <jjn1056 at yahoo.com>
+
 jshirley: J. Shirley <jshirley at gmail.com>
 
 konobi: Scott McWhirter

Modified: trunk/DBIx-Class/t/101populate_rs.t
===================================================================
--- trunk/DBIx-Class/t/101populate_rs.t	2007-06-25 01:51:40 UTC (rev 3527)
+++ trunk/DBIx-Class/t/101populate_rs.t	2007-06-25 22:55:24 UTC (rev 3528)
@@ -15,7 +15,7 @@
 use lib qw(t/lib);
 use DBICTest;
 
-plan tests => 98;
+plan tests => 120;
 
 
 ## ----------------------------------------------------------------------------
@@ -32,6 +32,76 @@
 
 
 ## ----------------------------------------------------------------------------
+## Schema populate Tests
+## ----------------------------------------------------------------------------
+
+SCHEMA: {
+
+	## Test to make sure that the old $schema->populate is using the new method
+	## for $resultset->populate when in void context and with sub objects.
+	
+	$schema->populate('Artist', [
+	
+		[qw/name cds/],
+		["001First Artist", [
+			{title=>"001Title1", year=>2000},
+			{title=>"001Title2", year=>2001},
+			{title=>"001Title3", year=>2002},
+		]],
+		["002Second Artist", []],
+		["003Third Artist", [
+			{title=>"003Title1", year=>2005},
+		]],
+	]);
+	
+	isa_ok $schema, 'DBIx::Class::Schema';
+	
+	my ($artist1, $artist2, $artist3) = $schema->resultset('Artist')->search({
+		name=>["001First Artist","002Second Artist","003Third Artist"]},
+		{order_by=>'name ASC'})->all;
+	
+	isa_ok  $artist1, 'DBICTest::Artist';
+	isa_ok  $artist2, 'DBICTest::Artist';
+	isa_ok  $artist3, 'DBICTest::Artist';
+	
+	ok $artist1->name eq '001First Artist', "Got Expected Artist Name for Artist001";
+	ok $artist2->name eq '002Second Artist', "Got Expected Artist Name for Artist002";
+	ok $artist3->name eq '003Third Artist', "Got Expected Artist Name for Artist003";
+	
+	ok $artist1->cds->count eq 3, "Got Right number of CDs for Artist1";
+	ok $artist2->cds->count eq 0, "Got Right number of CDs for Artist2";
+	ok $artist3->cds->count eq 1, "Got Right number of CDs for Artist3";
+	
+	ARTIST1CDS: {
+	
+		my ($cd1, $cd2, $cd3) = $artist1->cds->search(undef, {order_by=>'year ASC'});
+		
+		isa_ok $cd1, 'DBICTest::CD';
+		isa_ok $cd2, 'DBICTest::CD';
+		isa_ok $cd3, 'DBICTest::CD';
+		
+		ok $cd1->year == 2000;
+		ok $cd2->year == 2001;
+		ok $cd3->year == 2002;
+		
+		ok $cd1->title eq '001Title1';
+		ok $cd2->title eq '001Title2';
+		ok $cd3->title eq '001Title3';
+	}
+	
+	ARTIST3CDS: {
+	
+		my ($cd1) = $artist3->cds->search(undef, {order_by=>'year ASC'});
+		
+		isa_ok $cd1, 'DBICTest::CD';
+
+		ok $cd1->year == 2005;
+		ok $cd1->title eq '003Title1';
+	}	
+}
+
+
+## ----------------------------------------------------------------------------
 ## Array context tests
 ## ----------------------------------------------------------------------------
 




More information about the Bast-commits mailing list