mirror of
https://github.com/kamilwylegala/cakephp2-php8.git
synced 2025-01-18 18:46:17 +00:00
Merge branch 'master' into 2.6
This commit is contained in:
commit
48101e6bf5
3 changed files with 35 additions and 3 deletions
|
@ -1439,11 +1439,10 @@ class DboSource extends DataSource {
|
|||
protected function _fetchHasMany(Model $Model, $query, $ids) {
|
||||
$ids = array_unique($ids);
|
||||
|
||||
$query = str_replace('{$__cakeID__$}', implode(', ', $ids), $query);
|
||||
if (count($ids) > 1) {
|
||||
$query = str_replace('= (', 'IN (', $query);
|
||||
$query = str_replace('= ({$__cakeID__$}', 'IN ({$__cakeID__$}', $query);
|
||||
}
|
||||
|
||||
$query = str_replace('{$__cakeID__$}', implode(', ', $ids), $query);
|
||||
return $this->fetchAll($query, $Model->cacheQueries);
|
||||
}
|
||||
|
||||
|
|
|
@ -3431,6 +3431,34 @@ SQL;
|
|||
$this->assertEquals($expected, $result);
|
||||
}
|
||||
|
||||
/**
|
||||
* test find() generating usable virtual fields to use in query without modifying custom subqueries.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function testVirtualFieldsWithSubquery() {
|
||||
$this->loadFixtures('Article', 'Comment', 'User', 'Tag', 'ArticlesTag');
|
||||
$this->Dbo->virtualFieldSeparator = '__';
|
||||
$Article = ClassRegistry::init('Article');
|
||||
$commentsTable = $this->Dbo->fullTableName('comments', false, false);
|
||||
$Article->Comment->virtualFields = array(
|
||||
'extra' => 'SELECT id FROM ' . $commentsTable . ' WHERE id = (SELECT 1)',
|
||||
);
|
||||
$conditions = array('Article.id' => array(1, 2));
|
||||
$contain = array('Comment.extra');
|
||||
|
||||
$test = ConnectionManager::getDatasource('test');
|
||||
$test->getLog();
|
||||
$result = $Article->find('all', compact('conditions', 'contain'));
|
||||
|
||||
$expected = 'SELECT `Comment`.`id`, `Comment`.`article_id`, `Comment`.`user_id`, `Comment`.`comment`, `Comment`.`published`, `Comment`.`created`,' .
|
||||
' `Comment`.`updated`, (SELECT id FROM comments WHERE id = (SELECT 1)) AS `Comment__extra`' .
|
||||
' FROM `cakephp_test`.`comments` AS `Comment` WHERE `Comment`.`article_id` IN (1, 2)';
|
||||
|
||||
$log = $test->getLog();
|
||||
$this->assertTextEquals($expected, $log['log'][count($log['log']) - 2]['query']);
|
||||
}
|
||||
|
||||
/**
|
||||
* test conditions to generate query conditions for virtual fields
|
||||
*
|
||||
|
|
|
@ -32,3 +32,8 @@
|
|||
<strong><?php echo __d('cake_dev', 'Notice'); ?>: </strong>
|
||||
<?php echo __d('cake_dev', 'If you want to customize this error message, create %s', APP_DIR . DS . 'View' . DS . 'Errors' . DS . 'fatal_error.ctp'); ?>
|
||||
</p>
|
||||
<?php
|
||||
if (extension_loaded('xdebug')) {
|
||||
xdebug_print_function_stack();
|
||||
}
|
||||
?>
|
||||
|
|
Loading…
Add table
Reference in a new issue