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:
Ceeram 2011-05-20 13:43:19 +02:00 committed by mark_story
parent b3e57e0feb
commit 6afa21cb18
2 changed files with 43 additions and 1 deletions

View file

@ -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();

View file

@ -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,