my ($self, $ident, $select, $where, $attrs) = @_;
my $sql_maker = $self->sql_maker;
- my ($alias2source, $rs_alias) = $self->_resolve_ident_sources ($ident);
+ my $alias2source = $self->_resolve_ident_sources ($ident);
$attrs = {
%$attrs,
select => $select,
from => $ident,
where => $where,
- $rs_alias && $alias2source->{$rs_alias}
- ? ( _rsroot_rsrc => $alias2source->{$rs_alias} )
+
+ # limit dialects use this stuff
+ # yes, some CDBICompat crap does not supply an {alias} >.<
+ ( $attrs->{alias} and $alias2source->{$attrs->{alias}} )
+ ? ( _rsroot_rsrc => $alias2source->{$attrs->{alias}} )
: ()
,
};
$self->_resolve_aliastypes_from_select_args( $attrs->{from}, undef, undef, { group_by => $attrs->{group_by} } )
}
) {
- $complex_prefetch = ! defined first { $_ ne $rs_alias } keys %{ $grp_aliases->{grouping} || {} };
+ $complex_prefetch = ! defined first { $_ ne $attrs->{alias} } keys %{ $grp_aliases->{grouping} || {} };
}
$complex_prefetch ||= ( $attrs->{rows} && $attrs->{collapse} );
my ($self, $ident) = @_;
my $alias2source = {};
- my $rs_alias;
# the reason this is so contrived is that $ident may be a {from}
# structure, specifying multiple tables to join
if ( blessed $ident && $ident->isa("DBIx::Class::ResultSource") ) {
# this is compat mode for insert/update/delete which do not deal with aliases
$alias2source->{me} = $ident;
- $rs_alias = 'me';
}
elsif (ref $ident eq 'ARRAY') {
my $tabinfo;
if (ref $_ eq 'HASH') {
$tabinfo = $_;
- $rs_alias = $tabinfo->{-alias};
}
if (ref $_ eq 'ARRAY' and ref $_->[0] eq 'HASH') {
$tabinfo = $_->[0];
}
}
- return ($alias2source, $rs_alias);
+ return $alias2source;
}
# Takes $ident, \@column_names
# for all sources
sub _resolve_column_info {
my ($self, $ident, $colnames) = @_;
- my ($alias2src, $root_alias) = $self->_resolve_ident_sources($ident);
+ my $alias2src = $self->_resolve_ident_sources($ident);
my (%seen_cols, @auto_colnames);
$schema->storage->debug ($orig_debug);
}, 'distinct generally works with prefetch on deep search_related chains');
+# pathological "user knows what they're doing" case
+# lifted from production somewhere
+{
+ $schema->resultset('CD')
+ ->search({ cdid => [1,2] })
+ ->search_related('tracks', { position => [3,1] })
+ ->delete_all;
+
+ my $rs = $schema->resultset('CD')->search_related('tracks', {}, {
+ group_by => 'me.title',
+ columns => { title => 'me.title', max_trk => \ 'MAX(tracks.position)' },
+ });
+
+ is_deeply(
+ $rs->all_hri,
+ [
+ { title => "Caterwaulin' Blues", max_trk => 3 },
+ { title => "Come Be Depressed With Us", max_trk => 3 },
+ { title => "Forkful of bees", max_trk => 1 },
+ { title => "Generic Manufactured Singles", max_trk => 3 },
+ { title => "Spoonful of bees", max_trk => 1 },
+ ],
+ 'Expected nonsense',
+ );
+}
+
done_testing;