X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?a=blobdiff_plain;f=lib%2FDBIx%2FClass%2FResultSet.pm;h=ae39e270ba126a791db3455f86c7b5b4664cd324;hb=895b576d77f033255f80ebf7464a7f3f198ac98a;hp=c72b38bd3c44a5c3c1356b72eab8e2baf1cfdeef;hpb=e4773415182471889a8ac44f72dae1547e331307;p=dbsrgits%2FDBIx-Class.git diff --git a/lib/DBIx/Class/ResultSet.pm b/lib/DBIx/Class/ResultSet.pm index c72b38b..ae39e27 100644 --- a/lib/DBIx/Class/ResultSet.pm +++ b/lib/DBIx/Class/ResultSet.pm @@ -3,8 +3,8 @@ package DBIx::Class::ResultSet; use strict; use warnings; use overload - '0+' => \&count, - 'bool' => sub { 1; }, + '0+' => "count", + 'bool' => "_bool", fallback => 1; use Carp::Clan qw/^DBIx::Class/; use Data::Page; @@ -50,6 +50,10 @@ In the examples below, the following table classes are used: __PACKAGE__->belongs_to(artist => 'MyApp::Schema::Artist'); 1; +=head1 OVERLOADING + +If a resultset is used as a number it returns the C. However, if it is used as a boolean it is always true. So if you want to check if a result set has any results use C. C will always be true. + =head1 METHODS =head2 new @@ -929,7 +933,7 @@ Performs an SQL C with the same query as the resultset was built with to find the number of elements. If passed arguments, does a search on the resultset and counts the results of that. -Note: When using C with C, L emulates C +Note: When using C with C, L emulates C using C. Some databases (notably SQLite) do not support C with multiple columns. If you are using such a database, you should only use columns from the main table in your C @@ -987,6 +991,10 @@ sub _count { # Separated out so pager can get the full count return $count; } +sub _bool { + return 1; +} + =head2 count_literal =over 4 @@ -2078,10 +2086,10 @@ sub _merge_attr { $position++; } my ($b_key) = ( ref $b_element eq 'HASH' ) ? keys %{$b_element} : ($b_element); + if ($best_candidate->{score} == 0 || exists $seen_keys->{$b_key}) { push( @{$a}, $b_element ); } else { - $seen_keys->{$b_key} = 1; # don't merge the same key twice my $a_best = $a->[$best_candidate->{position}]; # merge a_best and b_element together and replace original with merged if (ref $a_best ne 'HASH') { @@ -2091,6 +2099,7 @@ sub _merge_attr { $a->[$best_candidate->{position}] = { $key => $self->_merge_attr($a_best->{$key}, $b_element->{$key}) }; } } + $seen_keys->{$b_key} = 1; # don't merge the same key twice } return $a; @@ -2203,7 +2212,7 @@ return a column named C in the above example. =over 4 Indicates additional columns to be selected from storage. Works the same as -L but adds columns to the selection. =back @@ -2211,7 +2220,7 @@ L