'A required group_by clause could not be constructed automatically due to a complex '
. 'order_by criteria. Either order_by columns only (no functions) or construct a suitable '
. 'group_by by hand'
- ) if $unprocessed_order_chunks;
+ ) if @$unprocessed_order_chunks;
}
# we already optimized $inner_from above
$from = [ @$from ];
+ # We'll need this in a moment
+ my $head_from = $from->[0];
+
# so first generate the outer_from, up to the substitution point
my @outer_from;
while (my $j = shift @$from) {
}
}
- # scan the *remaining* from spec against different attributes, and see which joins are needed
- # in what role
+ # scan the *remaining* from spec against different attributes, and see
+ # which joins are needed in what role - we briefly re-add the old "head"
+ # from node so that the join path is correct for the top join
my $outer_aliastypes =
- $self->_resolve_aliastypes_from_select_args( $from, $outer_select, $where, $outer_attrs );
+ $self->_resolve_aliastypes_from_select_args( [ $head_from, @$from ], $outer_select, $where, $outer_attrs );
# unroll parents
my ($outer_select_chain, $outer_restrict_chain) = map { +{
'A required group_by clause could not be constructed automatically due to a complex '
. 'order_by criteria. Either order_by columns only (no functions) or construct a suitable '
. 'group_by by hand'
- ) if $unprocessed_order_chunks;
+ ) if @$unprocessed_order_chunks;
}
next;
}
if ($next->{type} eq DQ_ALIAS) {
- if (my $source_name = $next->{alias}{'dbix-class.source_name'}) {
+ if (my $source_name = $next->{'dbix-class.source_name'}) {
my @cols = $schema->source($source_name)->columns;
- @col_map{@cols} = ($next->{as}) x @cols;
+ @col_map{@cols} = ($next->{to}) x @cols;
}
}
}
push @group_by, \$entry;
}
}
+ my @leftovers;
if ($order_by) {
my $order_dq = $conv->_order_by_to_dq($order_by);
while ($order_dq) {
push @group_by, \$order_dq->{by}
unless $group_seen{join('.',@el)};
}
+ } else {
+ push @leftovers, $order_dq->{by};
}
$order_dq = $order_dq->{from};
}
}
- \@group_by;
+ wantarray ? (\@group_by, \@leftovers) : \@group_by;
}
sub _resolve_ident_sources {