[Bast-commits] r6967 - in DBIx-Class/0.08/trunk: lib/DBIx/Class t/lib/DBICTest/Schema t/multi_create

ribasushi at dev.catalyst.perl.org ribasushi at dev.catalyst.perl.org
Fri Jul 3 14:36:33 GMT 2009


Author: ribasushi
Date: 2009-07-03 14:36:32 +0000 (Fri, 03 Jul 2009)
New Revision: 6967

Modified:
   DBIx-Class/0.08/trunk/lib/DBIx/Class/ResultSet.pm
   DBIx-Class/0.08/trunk/t/lib/DBICTest/Schema/Artwork.pm
   DBIx-Class/0.08/trunk/t/multi_create/multilev_single_PKeqFK.t
Log:
Extra test to demonstrate has_one working, and a POD clarification of multicreate

Modified: DBIx-Class/0.08/trunk/lib/DBIx/Class/ResultSet.pm
===================================================================
--- DBIx-Class/0.08/trunk/lib/DBIx/Class/ResultSet.pm	2009-07-03 13:07:49 UTC (rev 6966)
+++ DBIx-Class/0.08/trunk/lib/DBIx/Class/ResultSet.pm	2009-07-03 14:36:32 UTC (rev 6967)
@@ -2226,13 +2226,16 @@
 can also be passed an object representing the foreign row, and the
 value will be set to its primary key.
 
-To create related objects, pass a hashref for the value if the related
-item is a foreign key relationship (L<DBIx::Class::Relationship/belongs_to>),
-and use the name of the relationship as the key. (NOT the name of the field,
-necessarily). For C<has_many> and C<has_one> relationships, pass an arrayref
-of hashrefs containing the data for each of the rows to create in the foreign
-tables, again using the relationship name as the key.
+To create related objects, pass a hashref of related-object column values
+B<keyed on the relationship name>. If the relationship is of type C<multi>
+(L<DBIx::Class::Relationship/has_many>) - pass an arrayref of hashrefs.
+The process will correctly identify columns holding foreign keys, and will
+transparrently populate them from the keys of the corresponding relation.
+This can be applied recursively, and will work correctly for a structure
+with an arbitrary depth and width, as long as the relationships actually
+exists and the correct column data has been supplied.
 
+
 Instead of hashrefs of plain related data (key/value pairs), you may
 also pass new or inserted objects. New objects (not inserted yet, see
 L</new>), will be inserted into their appropriate tables.

Modified: DBIx-Class/0.08/trunk/t/lib/DBICTest/Schema/Artwork.pm
===================================================================
--- DBIx-Class/0.08/trunk/t/lib/DBICTest/Schema/Artwork.pm	2009-07-03 13:07:49 UTC (rev 6966)
+++ DBIx-Class/0.08/trunk/t/lib/DBICTest/Schema/Artwork.pm	2009-07-03 14:36:32 UTC (rev 6967)
@@ -7,6 +7,7 @@
 __PACKAGE__->add_columns(
   'cd_id' => {
     data_type => 'integer',
+    is_nullable => 0,
   },
 );
 __PACKAGE__->set_primary_key('cd_id');

Modified: DBIx-Class/0.08/trunk/t/multi_create/multilev_single_PKeqFK.t
===================================================================
--- DBIx-Class/0.08/trunk/t/multi_create/multilev_single_PKeqFK.t	2009-07-03 13:07:49 UTC (rev 6966)
+++ DBIx-Class/0.08/trunk/t/multi_create/multilev_single_PKeqFK.t	2009-07-03 14:36:32 UTC (rev 6967)
@@ -8,7 +8,7 @@
 
 sub mc_diag { diag (@_) if $ENV{DBIC_MULTICREATE_DEBUG} };
 
-plan tests => 16;
+plan tests => 26;
 
 my $schema = DBICTest->init_schema();
 
@@ -30,8 +30,30 @@
   might_have => 'artwork',
 };
 
+for my $type (qw/has_one might_have/) {
+
+  lives_ok (sub {
+
+    my $rel = $rels->{$type};
+    my $cd_title = "Simple test $type cd";
+
+    my $cd = $schema->resultset('CD')->create ({
+      artist => 1,
+      title => $cd_title,
+      year => 2008,
+      $rel => {},
+    });
+
+    isa_ok ($cd, 'DBICTest::CD', 'Main CD object created');
+    is ($cd->title, $cd_title, 'Correct CD title');
+
+    isa_ok ($cd->$rel, 'DBICTest::Artwork', 'Related artwork present');
+    ok ($cd->$rel->in_storage, 'And in storage');
+
+  }, "Simple $type creation");
+}
+
 my $artist_rs = $schema->resultset('Artist');
-
 for my $type (qw/has_one might_have/) {
 
   my $rel = $rels->{$type};




More information about the Bast-commits mailing list