@@ -261,11 +261,13 @@ private function getLazySerializeCode(string $propertyAccess): string
261261 if ($ descriptor instanceof InheritanceReferencePropertyDescriptor) {
262262 $ descriptor = $ descriptor ->getNonScalarReferencedPropertyDescriptor ();
263263 }
264+ $ indexName = ltrim ($ descriptor ->getVariableName (), '$ ' );
265+ $ columnGetterName = $ descriptor ->getGetterName ();
264266 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 " ;
266270 } elseif ($ descriptor instanceof ScalarBeanPropertyDescriptor) {
267- $ indexName = ltrim ($ descriptor ->getVariableName (), '$ ' );
268- $ columnGetterName = $ descriptor ->getGetterName ();
269271 $ rows [] = "' $ indexName' => $ propertyAccess-> $ columnGetterName() " ;
270272 } else {
271273 throw new TDBMException ('PropertyDescriptor of class ` ' . get_class ($ descriptor ) . '` cannot be serialized. ' );
@@ -277,6 +279,9 @@ private function getLazySerializeCode(string $propertyAccess): string
277279 private function getBeanPropertyDescriptor (string $ column ): AbstractBeanPropertyDescriptor
278280 {
279281 foreach ($ this ->foreignBeanDescriptor ->getBeanPropertyDescriptors () as $ descriptor ) {
282+ if ($ descriptor instanceof ObjectBeanPropertyDescriptor && in_array ($ column , $ descriptor ->getForeignKey ()->getLocalColumns (), true )) {
283+ return $ descriptor ;
284+ }
280285 if ($ descriptor instanceof ScalarBeanPropertyDescriptor && $ descriptor ->getColumnName () === $ column ) {
281286 return $ descriptor ;
282287 }
0 commit comments