[Dbix-class] Cross product joins

Peter Rabbitson rabbit+list at rabbit.us
Fri Jan 16 09:48:38 GMT 2009


Gavin Carr wrote:
> On Sun, Jan 11, 2009 at 09:47:17PM +1100, Gavin Carr wrote:
>> generates a hanging ON clause:
>>
>>   ERROR:  syntax error at or near "WHERE" at character 239 [for Statement
>>   "SELECT [...] FROM store s JOIN postcode p ON  WHERE ( p.postcode = ? )"
>>   with ParamValues: 1='12345']
> 
> Digging further, the following patch to DBIx::Class::Storage::DBI 
> seems to fix the hanging ON issue:
> 
> --- Storage/DBI.pm.dist 2009-01-11 21:31:53.000000000 +1100
> +++ Storage/DBI.pm  2009-01-11 21:48:51.000000000 +1100
> @@ -227,7 +227,9 @@
>      } else {
>        push(@sqlf, $self->_make_as($to));
>      }
> -    push(@sqlf, ' ON ', $self->_join_condition($on));
> +    if (my $join_condition = $self->_join_condition($on)) {
> +      push(@sqlf, ' ON ', $join_condition);
> +    }
>    }
>    return join('', @sqlf);
>  }
> 
> and cross joins are now working with that explicit 'from' I
> posted, which is great. 
> 
> We should perhaps add the 'cross' -join_type to the 'from'
> pod in DBIx::Class::ResultSet, if the list there is supposed to
> be definitive (?):
> 
> --- ResultSet.pm.dist   2009-01-11 22:24:05.000000000 +1100
> +++ ResultSet.pm        2009-01-11 22:24:34.000000000 +1100
> @@ -2519,7 +2519,7 @@
>    [
>      { <alias1> => <table1> },
>      [
> -      { <alias2> => <table2>, -join_type => 'inner|left|right' },
> +      { <alias2> => <table2>, -join_type => 'inner|left|right|cross' },
>        [], # nested JOIN (optional)
>        { <table1.column1> => <table2.column2>, ... (more conditions) },
>      ],
> 
> 

Could you amalgamate this into a proper patch with a test showing that
the from thing works? This way it will be reviewed properly and if sane
- merged to trunk.



More information about the DBIx-Class mailing list