Skip to content
Permalink
Browse files

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
  • Loading branch information...
markstory committed Aug 8, 2014
1 parent 7c8770d commit d114fa143197886527bf1c8f2df5b49eb15242d1
@@ -1865,7 +1865,7 @@ public function buildJoinStatement($join) {
'type' => null,
'alias' => null,
'table' => 'join_table',
'conditions' => array()
'conditions' => '',
), $join);
if (!empty($data['alias'])) {
@@ -1919,7 +1919,7 @@ public function buildStatement($query, Model $Model) {
* @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']})");
@@ -1197,6 +1197,11 @@ public static function joinStatements() {
'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',

0 comments on commit d114fa1

Please sign in to comment.
You can’t perform that action at this time.