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

matthewt at dev.catalyst.perl.org matthewt at dev.catalyst.perl.org
Wed Sep 24 14:12:51 BST 2008


Author: matthewt
Date: 2008-09-24 14:12:51 +0100 (Wed, 24 Sep 2008)
New Revision: 4846

Modified:
   DBIx-Class/0.08/trunk/lib/DBIx/Class/ResultSet.pm
   DBIx-Class/0.08/trunk/lib/DBIx/Class/ResultSource.pm
   DBIx-Class/0.08/trunk/t/66relationship.t
Log:
first cut at sanitising multi-create/new_related etc., a couple things don't work that -mostly- worked before but what does work is now reliable

Modified: DBIx-Class/0.08/trunk/lib/DBIx/Class/ResultSet.pm
===================================================================
--- DBIx-Class/0.08/trunk/lib/DBIx/Class/ResultSet.pm	2008-09-22 17:10:13 UTC (rev 4845)
+++ DBIx-Class/0.08/trunk/lib/DBIx/Class/ResultSet.pm	2008-09-24 13:12:51 UTC (rev 4846)
@@ -1520,6 +1520,11 @@
   $self->throw_exception( "new_result needs a hash" )
     unless (ref $values eq 'HASH');
   $self->throw_exception(
+    "Implicit construct invalid, condition was not resolveable on parent "
+    ."object"
+  ) if (defined $self->{cond}
+        && $self->{cond} eq $DBIx::Class::ResultSource::UNRESOLVABLE_CONDITION);
+  $self->throw_exception(
     "Can't abstract implicit construct, condition not a hash"
   ) if ($self->{cond} && !(ref $self->{cond} eq 'HASH'));
 

Modified: DBIx-Class/0.08/trunk/lib/DBIx/Class/ResultSource.pm
===================================================================
--- DBIx-Class/0.08/trunk/lib/DBIx/Class/ResultSource.pm	2008-09-22 17:10:13 UTC (rev 4845)
+++ DBIx-Class/0.08/trunk/lib/DBIx/Class/ResultSource.pm	2008-09-24 13:12:51 UTC (rev 4846)
@@ -825,6 +825,8 @@
 
 =cut
 
+our $UNRESOLVABLE_CONDITION = \'1 = 0';
+
 sub resolve_condition {
   my ($self, $cond, $as, $for) = @_;
   #warn %$cond;
@@ -843,7 +845,7 @@
           if ($for->in_storage) {
             $self->throw_exception("Column ${v} not loaded on ${for} trying to reolve relationship");
           }
-          return [ \'1 = 0' ];
+          return [ $UNRESOLVABLE_CONDITION ];
         }
         $ret{$k} = $for->get_column($v);
         #$ret{$k} = $for->get_column($v) if $for->has_column_loaded($v);

Modified: DBIx-Class/0.08/trunk/t/66relationship.t
===================================================================
--- DBIx-Class/0.08/trunk/t/66relationship.t	2008-09-22 17:10:13 UTC (rev 4845)
+++ DBIx-Class/0.08/trunk/t/66relationship.t	2008-09-24 13:12:51 UTC (rev 4846)
@@ -7,7 +7,7 @@
 
 my $schema = DBICTest->init_schema();
 
-plan tests => 63;
+plan tests => 64;
 
 # has_a test
 my $cd = $schema->resultset("CD")->find(4);
@@ -250,3 +250,13 @@
 cmp_ok($artist->cds->count, '==', 0, "Correct new #cds for artist");
 cmp_ok($nartist->cds->count, '==', 2, "Correct new #cds for artist");
 
+my $new_artist = $schema->resultset("Artist")->new_result({ 'name' => 'Depeche Mode' });
+# why must i tell him: make a new related from me and me is me? that works!
+# my $new_related_cd = $new_artist->new_related('cds', { 'title' => 'Leave in Silence', 'year' => 1982, 'artist' => $new_artist });
+my $new_related_cd = $new_artist->new_related('cds', { 'title' => 'Leave in Silence', 'year' => 1982});
+eval {
+       $new_artist->insert;
+       $new_related_cd->insert;
+};
+$@ && diag($@);
+ok($new_related_cd->in_storage, 'new_related_cd insert ok');




More information about the Bast-commits mailing list