@@ -258,15 +258,22 @@ private function getLazySerializeCode(string $propertyAccess): string
258
258
$ rows = [];
259
259
foreach ($ this ->getForeignKey ()->getUnquotedForeignColumns () as $ column ) {
260
260
$ descriptor = $ this ->getBeanPropertyDescriptor ($ column );
261
+ $ shouldFlatten = false ;
261
262
if ($ descriptor instanceof InheritanceReferencePropertyDescriptor) {
262
263
$ descriptor = $ descriptor ->getNonScalarReferencedPropertyDescriptor ();
264
+ $ shouldFlatten = true ;
263
265
}
266
+
264
267
$ indexName = ltrim ($ descriptor ->getVariableName (), '$ ' );
265
268
$ columnGetterName = $ descriptor ->getGetterName ();
266
269
if ($ descriptor instanceof ObjectBeanPropertyDescriptor) {
267
- $ varName = '$o ' . lcfirst ($ indexName );
268
- $ lazySerializeCode = $ descriptor ->getLazySerializeCode ($ varName );
269
- $ rows [] = "' $ indexName' => ( $ varName = $ propertyAccess-> $ columnGetterName()) ? $ lazySerializeCode : null " ;
270
+ if ($ shouldFlatten ) {
271
+ $ rows [] = trim ($ descriptor ->getLazySerializeCode ($ propertyAccess ), '[] ' );
272
+ } else {
273
+ $ varName = $ descriptor ->getSafeVariableName ();
274
+ $ lazySerializeCode = $ descriptor ->getLazySerializeCode ($ varName );
275
+ $ rows [] = "' $ indexName' => ( $ varName = $ propertyAccess-> $ columnGetterName()) ? $ lazySerializeCode : null " ;
276
+ }
270
277
} elseif ($ descriptor instanceof ScalarBeanPropertyDescriptor) {
271
278
$ rows [] = "' $ indexName' => $ propertyAccess-> $ columnGetterName() " ;
272
279
} else {
@@ -279,10 +286,10 @@ private function getLazySerializeCode(string $propertyAccess): string
279
286
private function getBeanPropertyDescriptor (string $ column ): AbstractBeanPropertyDescriptor
280
287
{
281
288
foreach ($ this ->foreignBeanDescriptor ->getBeanPropertyDescriptors () as $ descriptor ) {
282
- if ($ descriptor instanceof ObjectBeanPropertyDescriptor && in_array ( $ column , $ descriptor ->getForeignKey ()-> getLocalColumns (), true ) ) {
289
+ if ($ descriptor instanceof ScalarBeanPropertyDescriptor && $ descriptor ->getColumnName () === $ column ) {
283
290
return $ descriptor ;
284
291
}
285
- if ($ descriptor instanceof ScalarBeanPropertyDescriptor && $ descriptor ->getColumnName () === $ column ) {
292
+ if ($ descriptor instanceof ObjectBeanPropertyDescriptor && in_array ( $ column , $ descriptor ->getForeignKey ()-> getLocalColumns (), true ) ) {
286
293
return $ descriptor ;
287
294
}
288
295
}
0 commit comments