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
This commit is contained in:
nate 2008-03-08 20:08:15 +00:00
parent c096e20350
commit 58e6da6a5b
2 changed files with 10 additions and 0 deletions

View file

@ -729,6 +729,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);
}

View file

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