[Bast-commits] r4863 - in DBIx-Class/0.08/trunk: lib/DBIx/Class/Relationship t

matthewt at dev.catalyst.perl.org matthewt at dev.catalyst.perl.org
Wed Oct 1 00:25:33 BST 2008


Author: matthewt
Date: 2008-10-01 00:25:33 +0100 (Wed, 01 Oct 2008)
New Revision: 4863

Modified:
   DBIx-Class/0.08/trunk/lib/DBIx/Class/Relationship/Base.pm
   DBIx-Class/0.08/trunk/t/66relationship.t
Log:
fix new_related on uninserted objects to handle has_manys correctly

Modified: DBIx-Class/0.08/trunk/lib/DBIx/Class/Relationship/Base.pm
===================================================================
--- DBIx-Class/0.08/trunk/lib/DBIx/Class/Relationship/Base.pm	2008-09-30 12:48:35 UTC (rev 4862)
+++ DBIx-Class/0.08/trunk/lib/DBIx/Class/Relationship/Base.pm	2008-09-30 23:25:33 UTC (rev 4863)
@@ -193,8 +193,13 @@
     if ($cond eq $DBIx::Class::ResultSource::UNRESOLVABLE_CONDITION) {
       my $reverse = $source->reverse_relationship_info($rel);
       foreach my $rev_rel (keys %$reverse) {
-        $attrs->{related_objects}{$rev_rel} = $self;
-        Scalar::Util::weaken($attrs->{related_object}{$rev_rel});
+        if ($reverse->{$rev_rel}{attrs}{accessor} eq 'multi') {
+          $attrs->{related_objects}{$rev_rel} = [ $self ];
+          Scalar::Util::weaken($attrs->{related_object}{$rev_rel}[0]);
+        } else {
+          $attrs->{related_objects}{$rev_rel} = $self;
+          Scalar::Util::weaken($attrs->{related_object}{$rev_rel});
+        }
       }
     }
     if (ref $cond eq 'ARRAY') {

Modified: DBIx-Class/0.08/trunk/t/66relationship.t
===================================================================
--- DBIx-Class/0.08/trunk/t/66relationship.t	2008-09-30 12:48:35 UTC (rev 4862)
+++ DBIx-Class/0.08/trunk/t/66relationship.t	2008-09-30 23:25:33 UTC (rev 4863)
@@ -7,7 +7,7 @@
 
 my $schema = DBICTest->init_schema();
 
-plan tests => 64;
+plan tests => 65;
 
 # has_a test
 my $cd = $schema->resultset("CD")->find(4);
@@ -213,7 +213,11 @@
 my $undef_artist_cd = $schema->resultset("CD")->new_result({ 'title' => 'badgers', 'year' => 2007 });
 is($undef_artist_cd->has_column_loaded('artist'), '', 'FK not loaded');
 is($undef_artist_cd->search_related('artist')->count, 0, '0=1 search when FK does not exist and object not yet in db');
-
+eval{ 
+     $undef_artist_cd->related_resultset('artist')->new({name => 'foo'});
+};
+is( $@, '', "Object created on a resultset related to not yet inserted object");
+ 
 my $def_artist_cd = $schema->resultset("CD")->new_result({ 'title' => 'badgers', 'year' => 2007, artist => undef });
 is($def_artist_cd->has_column_loaded('artist'), 1, 'FK loaded');
 is($def_artist_cd->search_related('artist')->count, 0, 'closed search on null FK');




More information about the Bast-commits mailing list