|
|
@@ -576,4 +576,43 @@ class QueryRegressionTest extends TestCase {
|
|
|
$this->assertCount(3, $results->toArray());
|
|
|
}
|
|
|
|
|
|
+/**
|
|
|
+ * Checks that matching and contain can be called for the same belongsTo association
|
|
|
+ *
|
|
|
+ * @see https://github.com/cakephp/cakephp/issues/5463
|
|
|
+ * @return void
|
|
|
+ */
|
|
|
+ public function testFindMatchingAndContain() {
|
|
|
+ $table = TableRegistry::get('Articles');
|
|
|
+ $table->belongsTo('Authors');
|
|
|
+ $article = $table->find()
|
|
|
+ ->contain('Authors')
|
|
|
+ ->matching('Authors', function ($q) {
|
|
|
+ return $q->where(['Authors.id' => 1]);
|
|
|
+ })
|
|
|
+ ->first();
|
|
|
+ $this->assertNotNull($article->author);
|
|
|
+ $this->assertEquals($article->author, $article->_matchingData['Authors']);
|
|
|
+ }
|
|
|
+
|
|
|
+/**
|
|
|
+ * Checks that matching and contain can be called for the same belongsTo association
|
|
|
+ *
|
|
|
+ * @see https://github.com/cakephp/cakephp/issues/5463
|
|
|
+ * @return void
|
|
|
+ */
|
|
|
+ public function testFindMatchingAndContainWithSubquery() {
|
|
|
+ $table = TableRegistry::get('authors');
|
|
|
+ $table->hasMany('articles', ['strategy' => 'subquery']);
|
|
|
+ $table->articles->belongsToMany('tags');
|
|
|
+
|
|
|
+ $result = $table->find()
|
|
|
+ ->matching('articles.tags', function ($q) {
|
|
|
+ return $q->where(['tags.id' => 2]);
|
|
|
+ })
|
|
|
+ ->contain('articles');
|
|
|
+
|
|
|
+ $this->assertCount(2, $result->first()->articles);
|
|
|
+ }
|
|
|
+
|
|
|
}
|