diff --git a/cake/libs/model/datasources/dbo_source.php b/cake/libs/model/datasources/dbo_source.php index ec891e4e9..d4de95231 100644 --- a/cake/libs/model/datasources/dbo_source.php +++ b/cake/libs/model/datasources/dbo_source.php @@ -728,6 +728,7 @@ class DboSource extends DataSource { } if (!empty($ins)) { $query = str_replace('{$__cakeID__$}', '(' .join(', ', $ins) .')', $query); + $query = str_replace('= (', 'IN (', $query); $query = str_replace('= (', 'IN (', $query); $query = str_replace(' WHERE 1 = 1', '', $query); } diff --git a/cake/tests/cases/libs/model/model.test.php b/cake/tests/cases/libs/model/model.test.php index a038354a4..f1a020c0e 100644 --- a/cake/tests/cases/libs/model/model.test.php +++ b/cake/tests/cases/libs/model/model.test.php @@ -134,6 +134,15 @@ class ModelTest extends CakeTestCase { unset($this->Portfolio); } + function testHabtmFinderQuery() { + $this->loadFixtures('Article', 'Tag', 'ArticlesTag'); + $this->Article =& new Article(); + $this->Article->hasAndBelongsToMany['Tag']['finderQuery'] = 'SELECT Tag.id, Tag.tag, ArticlesTag.article_id, ArticlesTag.tag_id FROM tags AS Tag JOIN articles_tags AS ArticlesTag ON (ArticlesTag.article_id = {$__cakeID__$} AND ArticlesTag.tag_id = Tag.id)'; + $result = $this->Article->find('first'); + $expected = array(array('id' => '1', 'tag' => 'tag1'), array('id' => '2', 'tag' => 'tag2')); + $this->assertEqual($result['Tag'], $expected); + } + function testHasManyOptimization() { $this->loadFixtures('Project', 'Thread', 'Message', 'Bid'); $this->Project =& new Project();