mirror of
https://github.com/kamilwylegala/cakephp2-php8.git
synced 2024-11-15 11:28:25 +00:00
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:
parent
c096e20350
commit
58e6da6a5b
2 changed files with 10 additions and 0 deletions
|
@ -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);
|
||||
}
|
||||
|
|
|
@ -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();
|
||||
|
|
Loading…
Reference in a new issue