From 58e6da6a5b925b11c851d53267e35c98b271d0fc Mon Sep 17 00:00:00 2001 From: nate Date: Sat, 8 Mar 2008 20:08:15 +0000 Subject: [PATCH] Adding test case for custom 'finderQuery' for HABTM associations. Disproves #4100 git-svn-id: https://svn.cakephp.org/repo/branches/1.2.x.x@6521 3807eeeb-6ff5-0310-8944-8be069107fe0 --- cake/libs/model/datasources/dbo_source.php | 1 + cake/tests/cases/libs/model/model.test.php | 9 +++++++++ 2 files changed, 10 insertions(+) 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();