From: Peter Rabbitson Date: Thu, 12 Nov 2009 00:35:36 +0000 (+0000) Subject: Fix find on resultset with custom result_class X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?a=commitdiff_plain;h=0fcfe456c1255339f94fa1c218451760e65d24bc;p=dbsrgits%2FDBIx-Class-Historic.git Fix find on resultset with custom result_class --- diff --git a/Changes b/Changes index 25707cb..e2e4ae0 100644 --- a/Changes +++ b/Changes @@ -30,6 +30,8 @@ Revision history for DBIx::Class - Remove some IN workarounds, and require a recent version of SQLA instead - Improvements to populate's handling of mixed scalarref values + - Fixed regression losing result_class after $rs->find (introduced + in 0.08108) - POD improvements 0.08112 2009-09-21 10:57:00 (UTC) diff --git a/lib/DBIx/Class/ResultSet.pm b/lib/DBIx/Class/ResultSet.pm index 594c04a..9c278fe 100644 --- a/lib/DBIx/Class/ResultSet.pm +++ b/lib/DBIx/Class/ResultSet.pm @@ -357,9 +357,9 @@ sub search_rs { } my $rs = (ref $self)->new($self->result_source, $new_attrs); - if ($rows) { - $rs->set_cache($rows); - } + + $rs->set_cache($rows) if ($rows); + return $rs; } @@ -530,7 +530,7 @@ sub find { } # Run the query - my $rs = $self->search ($query, $attrs); + my $rs = $self->search ($query, {result_class => $self->result_class, %$attrs}); if (keys %{$rs->_resolved_attrs->{collapse}}) { my $row = $rs->next; carp "Query returned more than one row" if $rs->next; diff --git a/t/inflate/hri.t b/t/inflate/hri.t index 1d32dd6..292c943 100644 --- a/t/inflate/hri.t +++ b/t/inflate/hri.t @@ -1,7 +1,7 @@ use strict; -use warnings; +use warnings; -use Test::More qw(no_plan); +use Test::More; use lib qw(t/lib); use DBICTest; my $schema = DBICTest->init_schema(); @@ -9,7 +9,7 @@ my $schema = DBICTest->init_schema(); # Under some versions of SQLite if the $rs is left hanging around it will lock # So we create a scope here cos I'm lazy { - my $rs = $schema->resultset('CD'); + my $rs = $schema->resultset('CD')->search ({}, { order_by => 'cdid' }); # get the defined columns my @dbic_cols = sort $rs->result_source->columns; @@ -23,8 +23,10 @@ my $schema = DBICTest->init_schema(); my @hashref_cols = sort keys %$datahashref1; is_deeply( \@dbic_cols, \@hashref_cols, 'returned columns' ); -} + my $cd1 = $rs->find ({cdid => 1}); + is_deeply ( $cd1, $datahashref1, 'first/find return the same thing'); +} sub check_cols_of { my ($dbic_obj, $datahashref) = @_; @@ -135,3 +137,5 @@ is_deeply( [{ $artist->get_columns, cds => [] }], 'nested has_many prefetch without entries' ); + +done_testing;