From: David Kamholz Date: Tue, 1 Nov 2005 00:12:05 +0000 (+0000) Subject: - fix ResultSet bug when requesting a subset of columns X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?a=commitdiff_plain;h=90f3f5ff9b01602cc4bca97fac113d65fb8efb7c;p=dbsrgits%2FDBIx-Class-Historic.git - fix ResultSet bug when requesting a subset of columns - fix _create_ID to return undef when primary keys are not present --- diff --git a/lib/DBIx/Class/PK.pm b/lib/DBIx/Class/PK.pm index 3dba00d..3bb0740 100644 --- a/lib/DBIx/Class/PK.pm +++ b/lib/DBIx/Class/PK.pm @@ -136,6 +136,7 @@ sub ID { sub _create_ID { my ($class,%vals) = @_; + return undef unless 0 == grep { !defined } values %vals; $class = ref $class || $class; return join '|', $class, map { $_ . '=' . $vals{$_} } sort keys %vals; } diff --git a/lib/DBIx/Class/ResultSet.pm b/lib/DBIx/Class/ResultSet.pm index 4f702fa..ce28dff 100644 --- a/lib/DBIx/Class/ResultSet.pm +++ b/lib/DBIx/Class/ResultSet.pm @@ -118,7 +118,9 @@ sub next { sub _construct_object { my ($self, @row) = @_; - my @cols = $self->{class}->_select_columns; + my @cols = @{ $self->{attrs}{cols} }; + s/^me\.// for @cols; + @cols = grep { ! /\./ } @cols; my $new; unless ($self->{attrs}{prefetch}) { $new = $self->{class}->_row_to_object(\@cols, \@row); diff --git a/t/run/01core.tl b/t/run/01core.tl index d97f31f..a2c35b7 100644 --- a/t/run/01core.tl +++ b/t/run/01core.tl @@ -1,6 +1,6 @@ sub run_tests { -plan tests => 27; +plan tests => 28; my @art = DBICTest::Artist->search({ }, { order_by => 'name DESC'}); @@ -90,6 +90,9 @@ is($cd->year, 2005, 'set_columns ok'); $cd->discard_changes; +$cd = DBICTest::CD->search({ title => 'Spoonful of bees' }, { cols => ['title'] })->next; +is($cd->title, 'Spoonful of bees', 'subset of columns returned correctly'); + # insert_or_update $new = DBICTest::Track->new( { trackid => 100,