File tree Expand file tree Collapse file tree 2 files changed +22
-22
lines changed Expand file tree Collapse file tree 2 files changed +22
-22
lines changed Original file line number Diff line number Diff line change @@ -913,4 +913,26 @@ public function testPropertyNoPlugin()
913
913
$ association = new BelongsToMany ('Contacts.Tags ' , $ config );
914
914
$ this ->assertEquals ('tags ' , $ association ->property ());
915
915
}
916
+
917
+ /**
918
+ * Tests that fetching belongsToMany association will not force
919
+ * all fields being returned, but intead will honor the select() clause
920
+ *
921
+ * @see https://github.com/cakephp/cakephp/issues/7916
922
+ * @return void
923
+ */
924
+ public function testEagerLoadingBelongsToManyLimitedFields ()
925
+ {
926
+ $ table = TableRegistry::get ('Articles ' );
927
+ $ table ->belongsToMany ('Tags ' );
928
+ $ result = $ table
929
+ ->find ()
930
+ ->contain (['Tags ' => function ($ q ) {
931
+ return $ q ->select (['id ' ]);
932
+ }])
933
+ ->first ();
934
+
935
+ $ this ->assertNotEmpty ($ result ->tags [0 ]->id );
936
+ $ this ->assertEmpty ($ result ->tags [0 ]->name );
937
+ }
916
938
}
Original file line number Diff line number Diff line change @@ -1236,26 +1236,4 @@ public function testCountWithComplexOrderBy()
1236
1236
// Not executing the query first, just getting the count
1237
1237
$ this ->assertEquals (3 , $ query ->count ());
1238
1238
}
1239
-
1240
- /**
1241
- * Tests that fetching belongsToMany association will not force
1242
- * all fields being returned, but intead will honor the select() clause
1243
- *
1244
- * @see https://github.com/cakephp/cakephp/issues/7913
1245
- * @return void
1246
- */
1247
- public function testEagerLoadingBelongsToManyLimitedFields ()
1248
- {
1249
- $ table = TableRegistry::get ('Articles ' );
1250
- $ table ->belongsToMany ('Tags ' );
1251
- $ result = $ table
1252
- ->find ()
1253
- ->contain (['Tags ' => function ($ q ) {
1254
- return $ q ->select (['id ' ]);
1255
- }])
1256
- ->first ();
1257
-
1258
- $ this ->assertNotEmpty ($ result ->tags [0 ]->id );
1259
- $ this ->assertEmpty ($ result ->tags [0 ]->name );
1260
- }
1261
1239
}
You can’t perform that action at this time.
0 commit comments