Skip to content
Permalink
Browse files

Fixing issue in contain/mathching regarding dot notation

Previously it was impossible to use dot notation on two
different calls to matching/contain when part of the string was
shared (for example Articles.SpecialTags.Tags and Articles.SpecialTags.Authors)

The issue was that the second call would override the settings
created for the first one.
  • Loading branch information...
lorenzo committed Jun 15, 2015
1 parent c29c9e0 commit 60db9e0589f86ae9a764f35a4353c9a37ff0fc32
Showing with 35 additions and 3 deletions.
  1. +4 −1 src/ORM/EagerLoader.php
  2. +2 −2 tests/Fixture/SpecialTagsFixture.php
  3. +29 −0 tests/TestCase/ORM/QueryRegressionTest.php
@@ -281,7 +281,10 @@ protected function _reformatContain($associations, $original)
$options = isset($options['config']) ?
$options['config'] + $options['associations'] :
$options;
$options = $this->_reformatContain($options, []);
$options = $this->_reformatContain(
$options,
isset($pointer[$table]) ? $pointer[$table] : []
);
}
if ($options instanceof Closure) {
@@ -47,7 +47,7 @@ class SpecialTagsFixture extends TestFixture
* @var array
*/
public $records = [
['article_id' => 1, 'tag_id' => 3, 'highlighted' => false, 'highlighted_time' => null, 'author_id' => null],
['article_id' => 2, 'tag_id' => 1, 'highlighted' => true, 'highlighted_time' => '2014-06-01 10:10:00', 'author_id' => null]
['article_id' => 1, 'tag_id' => 3, 'highlighted' => false, 'highlighted_time' => null, 'author_id' => 1],
['article_id' => 2, 'tag_id' => 1, 'highlighted' => true, 'highlighted_time' => '2014-06-01 10:10:00', 'author_id' => 2]
];
}
@@ -968,4 +968,33 @@ public function testBooleanConditionsInContain()
$this->assertNotEmpty($result->tags, 'Missing tags');
$this->assertNotEmpty($result->tags[0]->_joinData, 'Missing join data');
}
/**
* Tests that it is possible to use matching with dot notation
* even when part of the part of the path in the dot notation is
* shared for two different calls
*
* @return void
*/
public function testDotNotationNotOverride()
{
$table = TableRegistry::get('Comments');
$articles = $table->belongsTo('Articles');
$specialTags = $articles->hasMany('SpecialTags');
$specialTags->belongsTo('Authors');
$specialTags->belongsTo('Tags');
$results = $table
->find()
->select(['name' => 'Authors.name', 'tag' => 'Tags.name'])
->matching('Articles.SpecialTags.Tags')
->matching('Articles.SpecialTags.Authors', function ($q) {
return $q->where(['Authors.id' => 2]);
})
->distinct()
->hydrate(false)
->toArray();
$this->assertEquals([['name' => 'nate', 'tag' => 'tag1']], $results);
}
}

0 comments on commit 60db9e0

Please sign in to comment.
You can’t perform that action at this time.