my @pri = $self->primary_columns;
my $dbh = $self->result_source->storage->dbh;
+ my ($schema,$table) = $self->table =~ /^(.+)\.(.+)$/ ? ($1,$2) : (undef,$self->table);
while (my $col = shift @pri) {
- my $info = $dbh->column_info(undef,undef,$self->table,$col)->fetchrow_arrayref;
+ my $info = $dbh->column_info(undef,$schema,$table,$col)->fetchrow_arrayref;
if (defined $info->[12] and $info->[12] =~
/^nextval\('"?([^"']+)"?'::(?:text|regclass)\)/)
{
$query->{$self->{attrs}{alias}.'.'.$_} = delete $query->{$_};
}
#warn Dumper($query);
- return $self->search($query)->next;
+ return $self->search($query,$attrs)->next;
}
=head2 search_related
sub STORABLE_thaw {
my ($self,$cloning,$serialized) = @_;
%$self = %{ thaw($serialized) };
- no strict 'refs';
$self->result_source($self->result_source_instance);
+# no strict 'refs';
# my $class = ${(ref $self) . '::ISA'}[0];
# my $schema = $self->result_source_instance->schema;
# $self->result_source($schema->source($class));
eval "use DBD::SQLite";
plan $@
? ( skip_all => 'needs DBD::SQLite for testing' )
- : ( tests => 31 );
+ : ( tests => 33 );
}
# test the abstract join => SQL generator
unlink 't/var/dbic.trace';
is($selects, 1, 'nested prefetch ran exactly 1 select statement (excluding column_info)');
+# start test for prefetch on find SELECT count
+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' });
+
+is($cd->{_inflated_column}{artist}->name, 'Caterwauler McCrae', 'artist prefetched correctly on find');
+
+# count the SELECTs
+DBI->trace(0, undef);
+$selects = 0;
+$trace = IO::File->new('t/var/dbic.trace', '<')
+ or die "Unable to read trace file";
+while (<$trace>) {
+ $selects++ if /SELECT(?!.*WHERE 1=0.*)/;
+}
+$trace->close;
+unlink 't/var/dbic.trace';
+is($selects, 1, 'find with prefetch ran exactly 1 select statement (excluding column_info)');
+
$rs = $schema->resultset('Tag')->search(
{},
{