Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
find with joins option now respects prefix set in database configurat…
…ion, fixes #1517

test to prove validity of ticket #1517
  • Loading branch information
ceeram authored and markstory committed Sep 28, 2011
1 parent b3e57e0 commit 6afa21c
Show file tree
Hide file tree
Showing 2 changed files with 43 additions and 1 deletion.
6 changes: 5 additions & 1 deletion cake/libs/model/model.php
Expand Up @@ -2132,7 +2132,11 @@ function find($conditions = null, $fields = array(), $order = null, $recursive =
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']);

This comment has been minimized.

Copy link
@rdcx

rdcx Nov 9, 2016

Contributor

This not being optional has ruined so many lives

}
}
$results = $db->read($this, $query);
$this->resetAssociations();

Expand Down
38 changes: 38 additions & 0 deletions cake/tests/cases/libs/model/model_integration.test.php
Expand Up @@ -148,6 +148,44 @@ function testDynamicBehaviorAttachment() {
$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,
Expand Down

0 comments on commit 6afa21c

Please sign in to comment.