X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?a=blobdiff_plain;f=lib%2FDBIx%2FClass%2FRow.pm;h=eafafe9965160aa90d57afef8c7779ab32514a64;hb=a4433d8e55074f96911ede2a922fced8b96743de;hp=36f5dd131035275cc0489448c4834517eb6ae7f0;hpb=b82c8a28bb4cb7d704496b8ce3966565d255d5b3;p=dbsrgits%2FDBIx-Class.git diff --git a/lib/DBIx/Class/Row.pm b/lib/DBIx/Class/Row.pm index 36f5dd1..eafafe9 100644 --- a/lib/DBIx/Class/Row.pm +++ b/lib/DBIx/Class/Row.pm @@ -758,9 +758,9 @@ sub get_inflated_columns { my %inflated; for my $col (keys %loaded_colinfo) { - my $acc = $loaded_colinfo{$col}{accessor}; - if (defined $acc) { - $inflated{$col} = $self->$acc; + if (exists $loaded_colinfo{$col}{accessor}) { + my $acc = $loaded_colinfo{$col}{accessor}; + $inflated{$col} = $self->$acc if defined $acc; } else { $inflated{$col} = $self->$col; @@ -1062,9 +1062,10 @@ sub inflate_result { my ($source_handle) = $source; if ($source->isa('DBIx::Class::ResultSourceHandle')) { - $source = $source_handle->resolve - } else { - $source_handle = $source->handle + $source = $source_handle->resolve + } + else { + $source_handle = $source->handle } my $new = { @@ -1073,17 +1074,29 @@ sub inflate_result { }; bless $new, (ref $class || $class); - my $schema; foreach my $pre (keys %{$prefetch||{}}) { - my $pre_val = $prefetch->{$pre}; - my $pre_source = $source->related_source($pre); - $class->throw_exception("Can't prefetch non-existent relationship ${pre}") - unless $pre_source; - if (ref($pre_val->[0]) eq 'ARRAY') { # multi - my @pre_objects; - for my $me_pref (@$pre_val) { + 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; + if (ref $prefetch->{$pre}[0] eq 'ARRAY') { + @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_objects; + for my $me_pref (@pre_vals) { + # FIXME - this should not be necessary # the collapser currently *could* return bogus elements with all # columns set to undef my $has_def; @@ -1098,31 +1111,16 @@ sub inflate_result { push @pre_objects, $pre_source->result_class->inflate_result( $pre_source, @$me_pref ); - } - - $new->related_resultset($pre)->set_cache(\@pre_objects); - } elsif (defined $pre_val->[0]) { - my $fetched; - unless ($pre_source->primary_columns == grep { exists $pre_val->[0]{$_} - and !defined $pre_val->[0]{$_} } $pre_source->primary_columns) - { - $fetched = $pre_source->result_class->inflate_result( - $pre_source, @{$pre_val}); - } - my $acc_type = $source->relationship_info($pre)->{attrs}{accessor} - or $class->throw_exception("No accessor type for prefetched $pre"); + } - if ($acc_type eq 'single') { - $new->{_relationship_data}{$pre} = $fetched; - } - elsif ($acc_type eq 'filter') { - $new->{_inflated_column}{$pre} = $fetched; - } - else { - $class->throw_exception("Implicit prefetch (via select/columns) not supported with accessor type '$acc_type'"); - } - $new->related_resultset($pre)->set_cache([ $fetched ]); + if ($accessor eq 'single') { + $new->{_relationship_data}{$pre} = $pre_objects[0]; } + elsif ($accessor eq 'filter') { + $new->{_inflated_column}{$pre} = $pre_objects[0]; + } + + $new->related_resultset($pre)->set_cache(\@pre_objects); } $new->in_storage (1);