@@ -261,11 +261,13 @@ private function getLazySerializeCode(string $propertyAccess): string
261
261
if ($ descriptor instanceof InheritanceReferencePropertyDescriptor) {
262
262
$ descriptor = $ descriptor ->getNonScalarReferencedPropertyDescriptor ();
263
263
}
264
+ $ indexName = ltrim ($ descriptor ->getVariableName (), '$ ' );
265
+ $ columnGetterName = $ descriptor ->getGetterName ();
264
266
if ($ descriptor instanceof ObjectBeanPropertyDescriptor) {
265
- $ rows [] = trim ($ descriptor ->getLazySerializeCode ($ propertyAccess ), '[] ' );
267
+ $ varName = '$o ' . lcfirst ($ indexName );
268
+ $ lazySerializeCode = $ descriptor ->getLazySerializeCode ($ varName );
269
+ $ rows [] = "' $ indexName' => ( $ varName = $ propertyAccess-> $ columnGetterName()) ? $ lazySerializeCode : null " ;
266
270
} elseif ($ descriptor instanceof ScalarBeanPropertyDescriptor) {
267
- $ indexName = ltrim ($ descriptor ->getVariableName (), '$ ' );
268
- $ columnGetterName = $ descriptor ->getGetterName ();
269
271
$ rows [] = "' $ indexName' => $ propertyAccess-> $ columnGetterName() " ;
270
272
} else {
271
273
throw new TDBMException ('PropertyDescriptor of class ` ' . get_class ($ descriptor ) . '` cannot be serialized. ' );
@@ -277,6 +279,9 @@ private function getLazySerializeCode(string $propertyAccess): string
277
279
private function getBeanPropertyDescriptor (string $ column ): AbstractBeanPropertyDescriptor
278
280
{
279
281
foreach ($ this ->foreignBeanDescriptor ->getBeanPropertyDescriptors () as $ descriptor ) {
282
+ if ($ descriptor instanceof ObjectBeanPropertyDescriptor && in_array ($ column , $ descriptor ->getForeignKey ()->getLocalColumns (), true )) {
283
+ return $ descriptor ;
284
+ }
280
285
if ($ descriptor instanceof ScalarBeanPropertyDescriptor && $ descriptor ->getColumnName () === $ column ) {
281
286
return $ descriptor ;
282
287
}
0 commit comments