X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?a=blobdiff_plain;f=lib%2FDBIx%2FClass%2FResultSet.pm;h=3677225c6de66bdfc8e617592445d5f4fcca8ece;hb=fb39747c525a55b3b569057867d971878457ede0;hp=206569a94e6988105ff2e393359f6a8e5fce804c;hpb=e4bb67275eafae2905d88eb061f1e5a7dca21d18;p=dbsrgits%2FDBIx-Class.git diff --git a/lib/DBIx/Class/ResultSet.pm b/lib/DBIx/Class/ResultSet.pm index 206569a..3677225 100644 --- a/lib/DBIx/Class/ResultSet.pm +++ b/lib/DBIx/Class/ResultSet.pm @@ -2623,15 +2623,27 @@ it were simply where-filtered without joins). For example: # works as expected: finds a 'table' row related to two x rows (abc and def) my $correctly_joined_rs = $rs2->search({'x.name' => 'def'}); +Another example of when one might use this would be to select a subset of +columns in a group by clause: + + my $rs = $schema->resultset('Bar')->search(undef, { + group_by => [qw{ id foo_id baz_id }], + })->as_subselect_rs->search(undef, { + columns => [qw{ id foo_id }] + }); + +In the above example normally columns would have to be equal to the group by, +but because we isolated the group by into a subselect the above works. + =cut sub as_subselect_rs { my $self = shift; return $self->result_source->resultset->search( undef, { - alias => 'me', + alias => $self->current_source_alias, from => [{ - me => $self->as_query, + $self->current_source_alias => $self->as_query, -alias => $self->current_source_alias, -source_handle => $self->result_source->handle, }]