Skip to content

Commit d114fa1

Browse files
committed
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
1 parent 7c8770d commit d114fa1

File tree

2 files changed

+7
-2
lines changed

2 files changed

+7
-2
lines changed

lib/Cake/Model/Datasource/DboSource.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1865,7 +1865,7 @@ public function buildJoinStatement($join) {
18651865
'type' => null,
18661866
'alias' => null,
18671867
'table' => 'join_table',
1868-
'conditions' => array()
1868+
'conditions' => '',
18691869
), $join);
18701870

18711871
if (!empty($data['alias'])) {
@@ -1919,7 +1919,7 @@ public function buildStatement($query, Model $Model) {
19191919
* @return string
19201920
*/
19211921
public function renderJoinStatement($data) {
1922-
if (strtoupper($data['type']) === 'CROSS') {
1922+
if (strtoupper($data['type']) === 'CROSS' || empty($data['conditions'])) {
19231923
return "{$data['type']} JOIN {$data['table']} {$data['alias']}";
19241924
}
19251925
return trim("{$data['type']} JOIN {$data['table']} {$data['alias']} ON ({$data['conditions']})");

lib/Cake/Test/Case/Model/Datasource/DboSourceTest.php

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1197,6 +1197,11 @@ public static function joinStatements() {
11971197
'table' => 'posts_tags',
11981198
'conditions' => array('1 = 1')
11991199
), 'CROSS JOIN cakephp.posts_tags AS PostsTag'),
1200+
array(array(
1201+
'type' => 'LEFT',
1202+
'alias' => 'PostsTag',
1203+
'table' => 'posts_tags',
1204+
), 'LEFT JOIN cakephp.posts_tags AS PostsTag'),
12001205
array(array(
12011206
'type' => 'LEFT',
12021207
'alias' => 'PostsTag',

0 commit comments

Comments
 (0)