X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?a=blobdiff_plain;f=lib%2FDBIx%2FClass%2FRow.pm;h=60c854bd94d2e1e68fb5e656e9c65da05ec4d76a;hb=ce9f555e55e767a287831c0fcccb337cc36905de;hp=1984d6c6333fd7f036cf196a2868b086b8c72f2c;hpb=5ef76b8b1094769245360ff8bf800fbde46119e6;p=dbsrgits%2FDBIx-Class.git diff --git a/lib/DBIx/Class/Row.pm b/lib/DBIx/Class/Row.pm index 1984d6c..60c854b 100644 --- a/lib/DBIx/Class/Row.pm +++ b/lib/DBIx/Class/Row.pm @@ -357,9 +357,11 @@ sub insert { # this ensures we fire store_column only once # (some asshats like overriding it) if ( - (! defined $current_rowdata{$_}) + (!exists $current_rowdata{$_}) or - ( $current_rowdata{$_} ne $returned_cols->{$_}) + (defined $current_rowdata{$_} xor defined $returned_cols->{$_}) + or + (defined $current_rowdata{$_} and $current_rowdata{$_} ne $returned_cols->{$_}) ); } @@ -499,7 +501,7 @@ sub update { $self->throw_exception( "Not in database" ) unless $self->in_storage; my $rows = $self->result_source->storage->update( - $self->result_source, \%to_update, $self->ident_condition + $self->result_source, \%to_update, $self->_storage_ident_condition ); if ($rows == 0) { $self->throw_exception( "Can't update ${self}: row not found" ); @@ -561,7 +563,7 @@ sub delete { $self->throw_exception( "Not in database" ) unless $self->in_storage; $self->result_source->storage->delete( - $self->result_source, $self->ident_condition + $self->result_source, $self->_storage_ident_condition ); delete $self->{_column_data_in_storage}; @@ -1137,23 +1139,38 @@ sub inflate_result { foreach my $pre (keys %{$prefetch||{}}) { - my $pre_source = $source->related_source($pre) - or $class->throw_exception("Can't prefetch non-existent relationship ${pre}"); - - my $accessor = $source->relationship_info($pre)->{attrs}{accessor} - or $class->throw_exception("No accessor for prefetched $pre"); - - my @pre_vals; + my (@pre_vals, $is_multi); if (ref $prefetch->{$pre}[0] eq 'ARRAY') { + $is_multi = 1; @pre_vals = @{$prefetch->{$pre}}; } - elsif ($accessor eq 'multi') { - $class->throw_exception("Implicit prefetch (via select/columns) not supported with accessor 'multi'"); - } else { @pre_vals = $prefetch->{$pre}; } + my $pre_source = try { + $source->related_source($pre) + } + catch { + $class->throw_exception(sprintf + + "Can't inflate manual prefetch into non-existent relationship '%s' from '%s', " + . "check the inflation specification (columns/as) ending in '%s.%s'.", + + $pre, + $source->source_name, + $pre, + (keys %{$pre_vals[0][0]})[0] || 'something.something...', + ); + }; + + my $accessor = $source->relationship_info($pre)->{attrs}{accessor} + or $class->throw_exception("No accessor type declared for prefetched $pre"); + + if (! $is_multi and $accessor eq 'multi') { + $class->throw_exception("Manual prefetch (via select/columns) not supported with accessor 'multi'"); + } + my @pre_objects; for my $me_pref (@pre_vals) { @@ -1370,7 +1387,7 @@ sub get_from_storage { $resultset = $resultset->search(undef, $attrs); } - return $resultset->find($self->ident_condition); + return $resultset->find($self->_storage_ident_condition); } =head2 discard_changes ($attrs?)