From: Matt S Trout Date: Wed, 24 Sep 2008 13:12:51 +0000 (+0000) Subject: first cut at sanitising multi-create/new_related etc., a couple things don't work... X-Git-Tag: v0.08240~350 X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?a=commitdiff_plain;h=8c368cf38b5f099a970c12b2f1a32936df2538ca;p=dbsrgits%2FDBIx-Class.git 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 --- diff --git a/lib/DBIx/Class/ResultSet.pm b/lib/DBIx/Class/ResultSet.pm index 50bbc10..f60bd81 100644 --- a/lib/DBIx/Class/ResultSet.pm +++ b/lib/DBIx/Class/ResultSet.pm @@ -1520,6 +1520,11 @@ sub new_result { $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')); diff --git a/lib/DBIx/Class/ResultSource.pm b/lib/DBIx/Class/ResultSource.pm index 2c71640..3ac1d3c 100644 --- a/lib/DBIx/Class/ResultSource.pm +++ b/lib/DBIx/Class/ResultSource.pm @@ -825,6 +825,8 @@ a related conditional from that object. =cut +our $UNRESOLVABLE_CONDITION = \'1 = 0'; + sub resolve_condition { my ($self, $cond, $as, $for) = @_; #warn %$cond; @@ -843,7 +845,7 @@ sub resolve_condition { 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); diff --git a/t/66relationship.t b/t/66relationship.t index 7e8ed2d..e262230 100644 --- a/t/66relationship.t +++ b/t/66relationship.t @@ -7,7 +7,7 @@ use DBICTest; 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 @@ $artist->cds->update({artist => $nartist->id}); 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');