Skip to content
Browse files

find with joins option now respects prefix set in database configurat…

…ion, fixes #1517

test to prove validity of ticket #1517
  • Loading branch information...
1 parent b3e57e0 commit 6afa21cb1888842fba27c826ffc62cdab7f243db @ceeram ceeram committed with markstory
Showing with 43 additions and 1 deletion.
  1. +5 −1 cake/libs/model/model.php
  2. +38 −0 cake/tests/cases/libs/model/model_integration.test.php
View
6 cake/libs/model/model.php
@@ -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']);
+ }
+ }
$results = $db->read($this, $query);
$this->resetAssociations();
View
38 cake/tests/cases/libs/model/model_integration.test.php
@@ -149,6 +149,44 @@ function testDynamicBehaviorAttachment() {
}
/**
+ * 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,
* or one connection will step on the other.

0 comments on commit 6afa21c

Please sign in to comment.
Something went wrong with that request. Please try again.