Skip to content

Commit 57523c1

Browse files
committed
Inheritance: Correct serialization on different pk column name
1 parent d5625f3 commit 57523c1

File tree

3 files changed

+16
-7
lines changed

3 files changed

+16
-7
lines changed

src/Utils/BeanDescriptor.php

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -298,6 +298,7 @@ private function getPropertiesForTable(Table $table): array
298298
continue 2;
299299
}
300300
}
301+
$propertyDescriptor = new ObjectBeanPropertyDescriptor($table, $fk, $this->namingStrategy, $this->beanNamespace, $this->annotationParser, $this->registry->getBeanForTableName($fk->getForeignTableName()));
301302
// Check that this property is not an inheritance relationship
302303
$parentRelationship = $this->schemaAnalyzer->getParentRelationship($table->getName());
303304
if ($parentRelationship !== null && $parentRelationship->getName() === $fk->getName()) {
@@ -306,12 +307,11 @@ private function getPropertiesForTable(Table $table): array
306307
$column,
307308
$this->namingStrategy,
308309
$this->annotationParser,
309-
new ScalarBeanPropertyDescriptor($table, $column, $this->namingStrategy, $this->annotationParser)
310+
$propertyDescriptor
310311
);
311312
} else {
312-
$beanPropertyDescriptors[] = new ObjectBeanPropertyDescriptor($table, $fk, $this->namingStrategy, $this->beanNamespace, $this->annotationParser, $this->registry->getBeanForTableName($fk->getForeignTableName()));;
313+
$beanPropertyDescriptors[] = $propertyDescriptor;
313314
}
314-
315315
} else {
316316
$beanPropertyDescriptors[] = new ScalarBeanPropertyDescriptor($table, $column, $this->namingStrategy, $this->annotationParser);
317317
}

src/Utils/ObjectBeanPropertyDescriptor.php

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -253,17 +253,21 @@ public function getJsonSerializeCode(): string
253253
return $code;
254254
}
255255

256-
private function getLazySerializeCode(string $propertyAccess): string
256+
public function getLazySerializeCode(string $propertyAccess): string
257257
{
258258
$rows = [];
259259
foreach ($this->getForeignKey()->getUnquotedForeignColumns() as $column) {
260260
$descriptor = $this->getBeanPropertyDescriptor($column);
261261
if ($descriptor instanceof ScalarReferencePropertyDescriptor) {
262262
$descriptor = $descriptor->getReferencedPropertyDescriptor();
263263
}
264-
$indexName = ltrim($descriptor->getVariableName(), '$');
265-
$columnGetterName = $descriptor->getGetterName();
266-
$rows[] = "'$indexName' => $propertyAccess->$columnGetterName()";
264+
if ($descriptor instanceof ObjectBeanPropertyDescriptor) {
265+
$rows[] = trim($descriptor->getLazySerializeCode($propertyAccess), '[]');
266+
} else {
267+
$indexName = ltrim($descriptor->getVariableName(), '$');
268+
$columnGetterName = $descriptor->getGetterName();
269+
$rows[] = "'$indexName' => $propertyAccess->$columnGetterName()";
270+
}
267271
}
268272
return '[' . implode(', ', $rows) . ']';
269273
}

src/Utils/ScalarReferencePropertyDescriptor.php

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,4 +34,9 @@ public function getReferencedPropertyDescriptor(): AbstractBeanPropertyDescripto
3434
{
3535
return $this->referencedPropertyDescriptor;
3636
}
37+
38+
public function getJsonSerializeCode(): string
39+
{
40+
return $this->referencedPropertyDescriptor->getJsonSerializeCode();
41+
}
3742
}

0 commit comments

Comments
 (0)