From: David Kamholz Date: Mon, 6 Feb 2006 00:32:28 +0000 (+0000) Subject: fix attrs on find X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?a=commitdiff_plain;h=c5b7d79941cd6942aeec1e81e1d4f7f9ad7eb62f;p=dbsrgits%2FDBIx-Class-Historic.git fix attrs on find --- diff --git a/lib/DBIx/Class/PK/Auto/Pg.pm b/lib/DBIx/Class/PK/Auto/Pg.pm index da49e9e..ad12dfa 100644 --- a/lib/DBIx/Class/PK/Auto/Pg.pm +++ b/lib/DBIx/Class/PK/Auto/Pg.pm @@ -24,8 +24,9 @@ sub get_autoinc_seq { 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)\)/) { diff --git a/lib/DBIx/Class/ResultSet.pm b/lib/DBIx/Class/ResultSet.pm index c65dc0b..32e4177 100644 --- a/lib/DBIx/Class/ResultSet.pm +++ b/lib/DBIx/Class/ResultSet.pm @@ -240,7 +240,7 @@ sub find { $query->{$self->{attrs}{alias}.'.'.$_} = delete $query->{$_}; } #warn Dumper($query); - return $self->search($query)->next; + return $self->search($query,$attrs)->next; } =head2 search_related diff --git a/lib/DBIx/Class/Serialize.pm b/lib/DBIx/Class/Serialize.pm index b032ad9..0db5176 100644 --- a/lib/DBIx/Class/Serialize.pm +++ b/lib/DBIx/Class/Serialize.pm @@ -13,8 +13,8 @@ sub STORABLE_freeze { 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)); diff --git a/t/run/16joins.tl b/t/run/16joins.tl index 14ca4bd..3ea71f1 100644 --- a/t/run/16joins.tl +++ b/t/run/16joins.tl @@ -7,7 +7,7 @@ BEGIN { eval "use DBD::SQLite"; plan $@ ? ( skip_all => 'needs DBD::SQLite for testing' ) - : ( tests => 31 ); + : ( tests => 33 ); } # test the abstract join => SQL generator @@ -161,6 +161,26 @@ $trace->close; 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( {}, {