diff --git a/tests/TestCase/ORM/Association/BelongsToManyTest.php b/tests/TestCase/ORM/Association/BelongsToManyTest.php index 9345fb972b0..00544b6281b 100644 --- a/tests/TestCase/ORM/Association/BelongsToManyTest.php +++ b/tests/TestCase/ORM/Association/BelongsToManyTest.php @@ -913,4 +913,26 @@ public function testPropertyNoPlugin() $association = new BelongsToMany('Contacts.Tags', $config); $this->assertEquals('tags', $association->property()); } + + /** + * Tests that fetching belongsToMany association will not force + * all fields being returned, but intead will honor the select() clause + * + * @see https://github.com/cakephp/cakephp/issues/7916 + * @return void + */ + public function testEagerLoadingBelongsToManyLimitedFields() + { + $table = TableRegistry::get('Articles'); + $table->belongsToMany('Tags'); + $result = $table + ->find() + ->contain(['Tags' => function ($q) { + return $q->select(['id']); + }]) + ->first(); + + $this->assertNotEmpty($result->tags[0]->id); + $this->assertEmpty($result->tags[0]->name); + } } diff --git a/tests/TestCase/ORM/QueryRegressionTest.php b/tests/TestCase/ORM/QueryRegressionTest.php index 5715badff9d..4292d03eb90 100644 --- a/tests/TestCase/ORM/QueryRegressionTest.php +++ b/tests/TestCase/ORM/QueryRegressionTest.php @@ -1236,26 +1236,4 @@ public function testCountWithComplexOrderBy() // Not executing the query first, just getting the count $this->assertEquals(3, $query->count()); } - - /** - * Tests that fetching belongsToMany association will not force - * all fields being returned, but intead will honor the select() clause - * - * @see https://github.com/cakephp/cakephp/issues/7913 - * @return void - */ - public function testEagerLoadingBelongsToManyLimitedFields() - { - $table = TableRegistry::get('Articles'); - $table->belongsToMany('Tags'); - $result = $table - ->find() - ->contain(['Tags' => function ($q) { - return $q->select(['id']); - }]) - ->first(); - - $this->assertNotEmpty($result->tags[0]->id); - $this->assertEmpty($result->tags[0]->name); - } }