From: Daniel Westermann-Clark Date: Wed, 10 May 2006 20:46:16 +0000 (+0000) Subject: - Fix error message for bad find usage X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?a=commitdiff_plain;h=a87eb97149a21ef44292cee9f4e006ebc7284155;p=dbsrgits%2FDBIx-Class-Historic.git - Fix error message for bad find usage - Restore backwards compatibility for e.g. $rs->find(id => $val) - Add a test for the $rs->find(id => $val) backwards compatibility --- diff --git a/lib/DBIx/Class/ResultSet.pm b/lib/DBIx/Class/ResultSet.pm index db58023..5b2473a 100644 --- a/lib/DBIx/Class/ResultSet.pm +++ b/lib/DBIx/Class/ResultSet.pm @@ -341,10 +341,14 @@ sub find { $hash = {}; @{$hash}{@cols} = @_; } + elsif (@_) { + # For backwards compatibility + $hash = {@_}; + } else { $self->throw_exception( "Arguments to find must be a hashref or match the number of columns in the " - . exists $attrs->{key} ? "$attrs->{key} unique constraint" : "primary key" + . (exists $attrs->{key} ? "$attrs->{key} unique constraint" : "primary key") ); } diff --git a/t/run/01core.tl b/t/run/01core.tl index 58e9c93..5287124 100644 --- a/t/run/01core.tl +++ b/t/run/01core.tl @@ -1,7 +1,7 @@ sub run_tests { my $schema = shift; -plan tests => 55; +plan tests => 57; # figure out if we've got a version of sqlite that is older than 3.2.6, in # which case COUNT(DISTINCT()) doesn't work @@ -86,6 +86,13 @@ is($new_again->name, 'Man With A Spoon', 'Retrieved correctly'); is($new_again->ID, 'DBICTest::Artist|artist|artistid=4', 'unique object id generated correctly'); +# Test backwards compatibility +{ + my $artist_by_hash = $schema->resultset('Artist')->find(artistid => 4); + is($artist_by_hash->name, 'Man With A Spoon', 'Retrieved correctly'); + is($artist_by_hash->ID, 'DBICTest::Artist|artist|artistid=4', 'unique object id generated correctly'); +} + is($schema->resultset("Artist")->count, 4, 'count ok'); # test find_or_new