@@ -258,15 +258,22 @@ private function getLazySerializeCode(string $propertyAccess): string
258258 $ rows = [];
259259 foreach ($ this ->getForeignKey ()->getUnquotedForeignColumns () as $ column ) {
260260 $ descriptor = $ this ->getBeanPropertyDescriptor ($ column );
261+ $ shouldFlatten = false ;
261262 if ($ descriptor instanceof InheritanceReferencePropertyDescriptor) {
262263 $ descriptor = $ descriptor ->getNonScalarReferencedPropertyDescriptor ();
264+ $ shouldFlatten = true ;
263265 }
266+
264267 $ indexName = ltrim ($ descriptor ->getVariableName (), '$ ' );
265268 $ columnGetterName = $ descriptor ->getGetterName ();
266269 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+ }
270277 } elseif ($ descriptor instanceof ScalarBeanPropertyDescriptor) {
271278 $ rows [] = "' $ indexName' => $ propertyAccess-> $ columnGetterName() " ;
272279 } else {
@@ -279,10 +286,10 @@ private function getLazySerializeCode(string $propertyAccess): string
279286 private function getBeanPropertyDescriptor (string $ column ): AbstractBeanPropertyDescriptor
280287 {
281288 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 ) {
283290 return $ descriptor ;
284291 }
285- if ($ descriptor instanceof ScalarBeanPropertyDescriptor && $ descriptor ->getColumnName () === $ column ) {
292+ if ($ descriptor instanceof ObjectBeanPropertyDescriptor && in_array ( $ column , $ descriptor ->getForeignKey ()-> getLocalColumns (), true ) ) {
286293 return $ descriptor ;
287294 }
288295 }
0 commit comments