From: Matt S Trout Date: Mon, 16 Apr 2012 14:03:40 +0000 (+0000) Subject: restore explicit aliases, fix up some join related stuff X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?a=commitdiff_plain;h=f4dc784718c4692e49e9944c31034fae02cf3c06;p=dbsrgits%2FDBIx-Class-Historic.git restore explicit aliases, fix up some join related stuff --- diff --git a/lib/DBIx/Class/ResultSet.pm b/lib/DBIx/Class/ResultSet.pm index 60c1f00..ae29895 100644 --- a/lib/DBIx/Class/ResultSet.pm +++ b/lib/DBIx/Class/ResultSet.pm @@ -1972,7 +1972,7 @@ sub _rs_update_delete { # 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) { diff --git a/lib/DBIx/Class/SQLMaker.pm b/lib/DBIx/Class/SQLMaker.pm index c418a3e..83f5da8 100644 --- a/lib/DBIx/Class/SQLMaker.pm +++ b/lib/DBIx/Class/SQLMaker.pm @@ -178,6 +178,10 @@ sub insert { next::method(@_); } +sub _recurse_from { + scalar shift->_render_sqla(table => \@_); +} + 1; =head1 OPERATORS diff --git a/lib/DBIx/Class/SQLMaker/Converter.pm b/lib/DBIx/Class/SQLMaker/Converter.pm index 7a85661..d6d1302 100644 --- a/lib/DBIx/Class/SQLMaker/Converter.pm +++ b/lib/DBIx/Class/SQLMaker/Converter.pm @@ -54,8 +54,8 @@ around _select_field_to_dq => sub { return +{ type => DQ_ALIAS, - alias => $field_dq, - as => $as + from => $field_dq, + to => $as }; } else { return $self->$orig(@_); @@ -104,9 +104,14 @@ around _table_to_dq => sub { 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}, + ) + : () + ) }; } } @@ -118,8 +123,6 @@ sub _join_to_dq { my $cur_dq = $self->_table_to_dq($from); -#{ local $Data::Dumper::Maxdepth = 3; ::Dwarn(\@joins); } - foreach my $join (@joins) { my ($to, $on) = @$join; @@ -127,12 +130,12 @@ sub _join_to_dq { 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, diff --git a/t/76joins.t b/t/76joins.t index 0fd511f..5562bdc 100644 --- a/t/76joins.t +++ b/t/76joins.t @@ -54,8 +54,8 @@ my @j3 = ( [ { 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 )' ; diff --git a/t/sqlmaker/core_quoted.t b/t/sqlmaker/core_quoted.t index a499878..a8a4af5 100644 --- a/t/sqlmaker/core_quoted.t +++ b/t/sqlmaker/core_quoted.t @@ -58,8 +58,8 @@ is_same_sql_bind( 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] ], @@ -335,7 +335,7 @@ $sql_maker->quote_char([qw/[ ]/]); 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' );