Skip to content

Commit 13bdda3

Browse files
committed
Add tests for empty expression objects in association conditions.
Empty expression objects currently cause invalid SQL when added to a query. I feel they should be no-ops instead. Refs #6568
1 parent 3915efe commit 13bdda3

File tree

1 file changed

+18
-0
lines changed

1 file changed

+18
-0
lines changed

tests/TestCase/ORM/QueryTest.php

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1861,6 +1861,24 @@ public function testContainWithQueryBuilderJoinableAssociation()
18611861
$this->assertEquals(1, $result[0]->author->id);
18621862
}
18631863

1864+
/**
1865+
* Test containing associations that have empty conditions.
1866+
*
1867+
* @return void
1868+
*/
1869+
public function testContainAssociationWithEmptyConditions()
1870+
{
1871+
$articles = TableRegistry::get('Articles');
1872+
$articles->belongsTo('Authors', [
1873+
'conditions' => function ($exp, $query) {
1874+
return $exp;
1875+
}
1876+
]);
1877+
$query = $articles->find('all')->contain(['Authors']);
1878+
$result = $query->toArray();
1879+
$this->assertCount(4, $result);
1880+
}
1881+
18641882
/**
18651883
* Tests the formatResults method
18661884
*

0 commit comments

Comments
 (0)