Skip to content

Commit 2eda480

Browse files
committed
Refactor
1 parent e69fc04 commit 2eda480

File tree

1 file changed

+9
-3
lines changed

1 file changed

+9
-3
lines changed

src/lib/AttributeResolver.php

+9-3
Original file line numberDiff line numberDiff line change
@@ -232,6 +232,7 @@ protected function resolveProperty(
232232
->setForeignKeyColumnName($property->fkColName)
233233
->setFakerStub($this->guessFakerStub($attribute, $property))
234234
->setTableName($this->componentSchema->resolveTableName($this->schemaName));
235+
235236
if ($property->isReference()) {
236237
if ($property->isVirtual()) {
237238
throw new InvalidDefinitionException('References not supported for virtual attributes');
@@ -279,10 +280,8 @@ protected function resolveProperty(
279280
$relation->asSelfReference();
280281
}
281282
$this->relations[$property->getName()] = $relation;
282-
if (!$property->isRefPointerToSelf() && $property->hasRefItems()) {
283-
$this->addInverseRelation($relatedClassName, $attribute, $property, $fkProperty);
284-
}
285283
}
284+
286285
if (!$property->isReference() && !$property->hasRefItems()) {
287286
[$min, $max] = $property->guessMinMax();
288287
$attribute->setIsVirtual($property->isVirtual())
@@ -337,7 +336,14 @@ protected function resolveProperty(
337336
)
338337
->asHasMany([$foreignPk => $this->componentSchema->getPkName()]);
339338
return;
339+
} else { # handle inverse relation
340+
if ($property->isReference()) {
341+
$relatedClassName = $property->getRefClassName();
342+
$fkProperty = $property->getTargetProperty();
343+
$this->addInverseRelation($relatedClassName, $attribute, $property, $fkProperty);
344+
}
340345
}
346+
341347
$relatedClassName = $property->getRefClassName();
342348
$relatedTableName = $property->getRefSchema()->resolveTableName($relatedClassName);
343349
if ($this->catchManyToMany(

0 commit comments

Comments
 (0)