@@ -245,28 +245,35 @@ public function contain($associations = null, $override = false) {
245
245
return $ this ;
246
246
}
247
247
248
- $ normalizer = function ($ associations ) use (&$ normalizer ) {
249
- $ result = [];
250
- foreach ((array )$ associations as $ table => $ options ) {
251
- if (is_int ($ table )) {
252
- $ table = $ options ;
253
- $ options = [];
254
- } elseif (is_array ($ options ) && !isset ($ this ->_containOptions [$ table ])) {
255
- $ options = $ normalizer ($ options );
256
- }
257
- $ result [$ table ] = $ options ;
258
- }
259
- return $ result ;
260
- };
261
-
262
248
$ old = $ this ->_containments ->getArrayCopy ();
263
- $ associations = array_merge ($ old , $ normalizer ($ associations ));
249
+ $ associations = array_merge ($ old , $ this -> _reformatContain ($ associations ));
264
250
$ this ->_containments ->exchangeArray ($ associations );
265
251
$ this ->_normalizedContainments = null ;
266
252
$ this ->_dirty = true ;
267
253
return $ this ;
268
254
}
269
255
256
+ /**
257
+ * Formats the containments array so that associations are always set as keys
258
+ * in the array.
259
+ *
260
+ * @param array $associations user provided containments array
261
+ * @return array
262
+ */
263
+ protected function _reformatContain ($ associations ) {
264
+ $ result = [];
265
+ foreach ((array )$ associations as $ table => $ options ) {
266
+ if (is_int ($ table )) {
267
+ $ table = $ options ;
268
+ $ options = [];
269
+ } elseif (is_array ($ options ) && !isset ($ this ->_containOptions [$ table ])) {
270
+ $ options = $ this ->_reformatContain ($ options );
271
+ }
272
+ $ result [$ table ] = $ options ;
273
+ }
274
+ return $ result ;
275
+ }
276
+
270
277
/**
271
278
* Returns the fully normalized array of associations that should be eagerly
272
279
* loaded. The normalized array will restructure the original one by sorting
@@ -275,7 +282,6 @@ public function contain($associations = null, $override = false) {
275
282
* Additionally it will set an 'instance' key per association containing the
276
283
* association instance from the corresponding source table
277
284
*
278
- *
279
285
* @return array
280
286
*/
281
287
public function normalizedContainments () {
0 commit comments