Revision history for DBIx::Class
+ - allow specification of related columns via cols attr when primary
+ keys of the related table are not fetched
- add horrific fix to make Oracle's retarded limit syntax work
0.05003 2006-02-08 17:50:20
PRE: foreach my $pre (keys %{$prefetch||{}}) {
my $pre_source = $source->related_source($pre);
$class->throw_exception("Can't prefetch non-existant relationship ${pre}") unless $pre_source;
- my $fetched = $pre_source->result_class->inflate_result(
- $pre_source, @{$prefetch->{$pre}});
+ my $fetched;
+ unless ($pre_source->primary_columns == grep { exists $prefetch->{$pre}[0]{$_}
+ and !defined $prefetch->{$pre}[0]{$_} } $pre_source->primary_columns)
+ {
+ $fetched = $pre_source->result_class->inflate_result(
+ $pre_source, @{$prefetch->{$pre}});
+ }
my $accessor = $source->relationship_info($pre)->{attrs}{accessor};
$class->throw_exception("No accessor for prefetched $pre")
unless defined $accessor;
- PRIMARY: foreach my $pri ($pre_source->primary_columns) {
- unless (defined $fetched->get_column($pri)) {
- undef $fetched;
- last PRIMARY;
- }
- }
if ($accessor eq 'single') {
$new->{_relationship_data}{$pre} = $fetched;
} elsif ($accessor eq 'filter') {
eval "use DBD::SQLite";
plan $@
? ( skip_all => 'needs DBD::SQLite for testing' )
- : ( tests => 40 );
+ : ( tests => 41 );
}
# test the abstract join => SQL generator
unlink 't/var/dbic.trace';
is($selects, 1, 'prefetch ran only 1 select statement');
+# test for partial prefetch via cols attr
+my $cd = $schema->resultset('CD')->find(1,
+ {
+ cols => [qw/title artist.name/],
+ join => 'artist'
+ }
+);
+ok(eval { $cd->artist->name eq 'Caterwauler McCrae' }, 'single related column prefetched');
+
# start test for nested prefetch SELECT count
unlink 't/var/dbic.trace' if -e 't/var/dbic.trace';
DBI->trace(1, 't/var/dbic.trace');
unlink 't/var/dbic.trace' if -e 't/var/dbic.trace';
DBI->trace(1, 't/var/dbic.trace');
-my $cd = $schema->resultset('CD')->find(1, { prefetch => 'artist' });
+$cd = $schema->resultset('CD')->find(1, { prefetch => 'artist' });
is($cd->{_inflated_column}{artist}->name, 'Caterwauler McCrae', 'artist prefetched correctly on find');