Skip to content

Commit bd3f653

Browse files
committed
Deeper Composite FK: Fix flatten in case of inheritance
1 parent 94e51b0 commit bd3f653

File tree

2 files changed

+13
-6
lines changed

2 files changed

+13
-6
lines changed

src/Utils/AbstractBeanPropertyDescriptor.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -67,7 +67,7 @@ abstract public function getPhpType(): string;
6767
*/
6868
public function getParamAnnotation(): ParamTag
6969
{
70-
return new ParamTag($this->getVariableName(), [ $this->getPhpType() ]);
70+
return new ParamTag($this->getSafeVariableName(), [ $this->getPhpType() ]);
7171
}
7272

7373
public function getVariableName(): string

src/Utils/ObjectBeanPropertyDescriptor.php

Lines changed: 12 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -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

Comments
 (0)