@@ -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