mirror of
https://github.com/kamilwylegala/cakephp2-php8.git
synced 2024-11-15 03:18:26 +00:00
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:
parent
7c8770d577
commit
d114fa1431
2 changed files with 7 additions and 2 deletions
|
@ -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']})");
|
||||
|
|
|
@ -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',
|
||||
|
|
Loading…
Reference in a new issue