# make a new $rs selecting only the PKs (that's all we really need for the subq)
delete @{$attrs}{qw/collapse select _prefetch_selector_range as/};
$attrs->{columns} = [ map { "$attrs->{alias}.$_" } @$idcols ];
- $attrs->{group_by} = \ ''; # FIXME - this is an evil hack, it causes the optimiser to kick in and throw away the LEFT joins
+ #$attrs->{group_by} = \ ''; # FIXME - this is an evil hack, it causes the optimiser to kick in and throw away the LEFT joins
my $subrs = (ref $self)->new($rsrc, $attrs);
if (@$idcols == 1) {
next::method(@_);
}
+sub _recurse_from {
+ scalar shift->_render_sqla(table => \@_);
+}
+
1;
=head1 OPERATORS
return +{
type => DQ_ALIAS,
- alias => $field_dq,
- as => $as
+ from => $field_dq,
+ to => $as
};
} else {
return $self->$orig(@_);
type => DQ_ALIAS,
from => $self->_table_to_dq($table),
to => $as,
- 'dbix-class.source_name' => $spec->{-rsrc}->source_name,
- 'dbix-class.join_path' => $spec->{-join_path},
- 'dbix-class.is_single' => $spec->{-is_single},
+ ($spec->{-rsrc}
+ ? (
+ 'dbix-class.source_name' => $spec->{-rsrc}->source_name,
+ 'dbix-class.join_path' => $spec->{-join_path},
+ 'dbix-class.is_single' => $spec->{-is_single},
+ )
+ : ()
+ )
};
}
}
my $cur_dq = $self->_table_to_dq($from);
-#{ local $Data::Dumper::Maxdepth = 3; ::Dwarn(\@joins); }
-
foreach my $join (@joins) {
my ($to, $on) = @$join;
my $to_jt = ref($to) eq 'ARRAY' ? $to->[0] : $to;
my $join_type;
if (ref($to_jt) eq 'HASH' and defined($to_jt->{-join_type})) {
- $join_type = $to_jt->{-join_type};
+ $join_type = lc($to_jt->{-join_type});
$join_type =~ s/^\s+ | \s+$//xg;
undef($join_type) unless $join_type =~ s/^(left|right).*/$1/;
}
- $join_type ||= $self->{_default_jointype};
+ $join_type ||= lc($self->{_default_jointype});
$cur_dq = +{
type => DQ_JOIN,
[ { father => 'person', -join_type => 'inner' }, { 'father.person_id' => 'child.father_id' }, ],
[ { mother => 'person', -join_type => 'inner' }, { 'mother.person_id' => 'child.mother_id' } ],
);
-$match = 'person child INNER JOIN person father ON ( father.person_id = '
- . 'child.father_id ) INNER JOIN person mother ON ( mother.person_id '
+$match = 'person child JOIN person father ON ( father.person_id = '
+ . 'child.father_id ) JOIN person mother ON ( mother.person_id '
. '= child.mother_id )'
;
q/
SELECT `me`.`cdid`, COUNT( `tracks`.`cd` ), MIN( `me`.`year` ) AS `minyear`
FROM `cd` `me`
- JOIN `artist` ON ( `artist`.`artistid` = `me`.`artist` )
- LEFT JOIN `tracks` ON ( `tracks`.`cd` = `me`.`cdid` )
+ JOIN `artist` `artist` ON ( `artist`.`artistid` = `me`.`artist` )
+ LEFT JOIN `tracks` `tracks` ON ( `tracks`.`cd` = `me`.`cdid` )
WHERE ( `artist`.`name` = ? AND `me`.`year` = ? )
/,
[ ['artist.name' => 'Caterwauler McCrae'], ['me.year' => 2001] ],
is_same_sql_bind(
$sql, \@bind,
- q/SELECT MAX ( [rank] ) AS [max_rank], [rank], COUNT( * ) AS [cnt] FROM [cd] [me] JOIN [artist] ON ( [artist].[artistid] = [me].[artist] ) WHERE ( [artist].[name] = ? AND [me].[year] = ? )/, [ ['artist.name' => 'Caterwauler McCrae'], ['me.year' => 2001] ],
+ q/SELECT MAX ( [rank] ) AS [max_rank], [rank], COUNT( * ) AS [cnt] FROM [cd] [me] JOIN [artist] [artist] ON ( [artist].[artistid] = [me].[artist] ) WHERE ( [artist].[name] = ? AND [me].[year] = ? )/, [ ['artist.name' => 'Caterwauler McCrae'], ['me.year' => 2001] ],
'got correct SQL and bind parameters for count query with bracket quoting'
);