From: Matt S Trout Date: Sun, 17 Nov 2013 05:38:50 +0000 (+0000) Subject: STRAIGHT_JOIN support for MySQL X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?a=commitdiff_plain;h=698e7918034954e345f1af7b4ce269862f728e7f;p=dbsrgits%2FDBIx-Class.git STRAIGHT_JOIN support for MySQL --- diff --git a/lib/DBIx/Class/SQLMaker/Converter.pm b/lib/DBIx/Class/SQLMaker/Converter.pm index 86b3ff2..858bc69 100644 --- a/lib/DBIx/Class/SQLMaker/Converter.pm +++ b/lib/DBIx/Class/SQLMaker/Converter.pm @@ -256,31 +256,36 @@ sub _join_to_dq { } foreach my $join (@joins) { - my ($to, $on) = @$join; - - # check whether a join type exists - 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 = lc($to_jt->{-join_type}); - $join_type =~ s/^\s+ | \s+$//xg; - undef($join_type) unless $join_type =~ s/^(left|right).*/$1/; - } - - $cur_dq = +{ - type => DQ_JOIN, - ($join_type ? (outer => $join_type) : ()), - left => $cur_dq, - right => $self->_table_to_dq($to), - ($on - ? (on => $self->_expr_to_dq($self->_expand_join_condition($on))) - : ()), - }; + $cur_dq = $self->_generate_join_node($join, $cur_dq); } return $cur_dq; } +sub _generate_join_node { + my ($self, $join, $inner) = @_; + my ($to, $on) = @$join; + + # check whether a join type exists + 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 = lc($to_jt->{-join_type}); + $join_type =~ s/^\s+ | \s+$//xg; + undef($join_type) unless $join_type =~ s/^(left|right).*/$1/; + } + + return +{ + type => DQ_JOIN, + ($join_type ? (outer => $join_type) : ()), + left => $inner, + right => $self->_table_to_dq($to), + ($on + ? (on => $self->_expr_to_dq($self->_expand_join_condition($on))) + : ()), + }; +} + sub _expand_join_condition { my ($self, $cond) = @_; diff --git a/lib/DBIx/Class/SQLMaker/Converter/MySQL.pm b/lib/DBIx/Class/SQLMaker/Converter/MySQL.pm index 727eef5..0d62856 100644 --- a/lib/DBIx/Class/SQLMaker/Converter/MySQL.pm +++ b/lib/DBIx/Class/SQLMaker/Converter/MySQL.pm @@ -80,4 +80,14 @@ sub _mangle_mutation_dq { } $dq; }; +around _generate_join_node => sub { + my ($orig, $self) = (shift, shift); + my $node = $self->$orig(@_); + my $to_jt = ref($_[0][0]) eq 'ARRAY' ? $_[0][0][0] : $_[0][0]; + if (ref($to_jt) eq 'HASH' and ($to_jt->{-join_type}||'') =~ /^STRAIGHT\z/i) { + $node->{'Data::Query::Renderer::SQL::MySQL.straight_join'} = 1; + } + return $node; +}; + 1;