Skip to content

Commit

Permalink
Update join building to not error out on empty conditions.
Browse files Browse the repository at this point in the history
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 d114fa1
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 2 deletions.
4 changes: 2 additions & 2 deletions lib/Cake/Model/Datasource/DboSource.php
Expand Up @@ -1865,7 +1865,7 @@ public function buildJoinStatement($join) {
'type' => null,
'alias' => null,
'table' => 'join_table',
'conditions' => array()
'conditions' => '',
), $join);

if (!empty($data['alias'])) {
Expand Down Expand Up @@ -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']})");
Expand Down
5 changes: 5 additions & 0 deletions lib/Cake/Test/Case/Model/Datasource/DboSourceTest.php
Expand Up @@ -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',
Expand Down

0 comments on commit d114fa1

Please sign in to comment.