Update join building to not error out on empty conditions.

When conditions are empty we can assume one of two things:

* The person made a mistake.
* The person is doing the join conditions in the where clause.

In both cases we should attempt to generate proper SQL.

Fixes #4189
This commit is contained in:
mark_story 2014-08-08 10:02:09 -04:00
parent 7c8770d577
commit d114fa1431
2 changed files with 7 additions and 2 deletions

View file

@ -1865,7 +1865,7 @@ class DboSource extends DataSource {
'type' => null,
'alias' => null,
'table' => 'join_table',
'conditions' => array()
'conditions' => '',
), $join);
if (!empty($data['alias'])) {
@ -1919,7 +1919,7 @@ class DboSource extends DataSource {
* @return string
*/
public function renderJoinStatement($data) {
if (strtoupper($data['type']) === 'CROSS') {
if (strtoupper($data['type']) === 'CROSS' || empty($data['conditions'])) {
return "{$data['type']} JOIN {$data['table']} {$data['alias']}";
}
return trim("{$data['type']} JOIN {$data['table']} {$data['alias']} ON ({$data['conditions']})");

View file

@ -1197,6 +1197,11 @@ class DboSourceTest extends CakeTestCase {
'table' => 'posts_tags',
'conditions' => array('1 = 1')
), 'CROSS JOIN cakephp.posts_tags AS PostsTag'),
array(array(
'type' => 'LEFT',
'alias' => 'PostsTag',
'table' => 'posts_tags',
), 'LEFT JOIN cakephp.posts_tags AS PostsTag'),
array(array(
'type' => 'LEFT',
'alias' => 'PostsTag',