mirror of
https://github.com/kamilwylegala/cakephp2-php8.git
synced 2025-01-19 11:06:15 +00:00
find with joins option now respects prefix set in database configuration, fixes #1517
test to prove validity of ticket #1517
This commit is contained in:
parent
b3e57e0feb
commit
6afa21cb18
2 changed files with 43 additions and 1 deletions
|
@ -2132,7 +2132,11 @@ class Model extends Overloadable {
|
|||
if (!$db =& ConnectionManager::getDataSource($this->useDbConfig)) {
|
||||
return false;
|
||||
}
|
||||
|
||||
if (!empty($query['joins']) && is_array($query['joins'])) {
|
||||
foreach($query['joins'] as $i => $join) {
|
||||
$query['joins'][$i]['table'] = $db->fullTableName($join['table']);
|
||||
}
|
||||
}
|
||||
$results = $db->read($this, $query);
|
||||
$this->resetAssociations();
|
||||
|
||||
|
|
|
@ -148,6 +148,44 @@ class ModelIntegrationTest extends BaseModelTest {
|
|||
$this->assertFalse(isset($TestModel->Behaviors->Tree));
|
||||
}
|
||||
|
||||
/**
|
||||
* testFindWithJoinsOption method
|
||||
*
|
||||
* @access public
|
||||
* @return void
|
||||
*/
|
||||
function testFindWithJoinsOption() {
|
||||
$this->loadFixtures('Article', 'User');
|
||||
$TestUser =& new User();
|
||||
|
||||
$options = array (
|
||||
'fields' => array(
|
||||
'user',
|
||||
'Article.published',
|
||||
),
|
||||
'joins' => array (
|
||||
array (
|
||||
'table' => 'articles',
|
||||
'alias' => 'Article',
|
||||
'type' => 'LEFT',
|
||||
'conditions' => array(
|
||||
'User.id = Article.user_id',
|
||||
),
|
||||
),
|
||||
),
|
||||
'group' => array('User.user'),
|
||||
'recursive' => -1,
|
||||
);
|
||||
$result = $TestUser->find('all', $options);
|
||||
$expected = array(
|
||||
array('User' => array('user' => 'garrett'), 'Article' => array('published' => '')),
|
||||
array('User' => array('user' => 'larry'), 'Article' => array('published' => 'Y')),
|
||||
array('User' => array('user' => 'mariano'), 'Article' => array('published' => 'Y')),
|
||||
array('User' => array('user' => 'nate'), 'Article' => array('published' => ''))
|
||||
);
|
||||
$this->assertEqual($result, $expected);
|
||||
}
|
||||
|
||||
/**
|
||||
* Tests cross database joins. Requires $test and $test2 to both be set in DATABASE_CONFIG
|
||||
* NOTE: When testing on MySQL, you must set 'persistent' => false on *both* database connections,
|
||||
|
|
Loading…
Add table
Reference in a new issue