@@ -60,11 +60,6 @@ class AttributeResolver
6060
6161 private ?Config $ config ;
6262
63- /**
64- * @var AttributeRelation[]|array
65- */
66- public array $ inverseRelations = [];
67-
6863 public function __construct (string $ schemaName , ComponentSchema $ schema , JunctionSchemas $ junctions , ?Config $ config = null )
6964 {
7065 $ this ->schemaName = $ schemaName ;
@@ -232,6 +227,7 @@ protected function resolveProperty(
232227 ->setForeignKeyColumnName ($ property ->fkColName )
233228 ->setFakerStub ($ this ->guessFakerStub ($ attribute , $ property ))
234229 ->setTableName ($ this ->componentSchema ->resolveTableName ($ this ->schemaName ));
230+
235231 if ($ property ->isReference ()) {
236232 if ($ property ->isVirtual ()) {
237233 throw new InvalidDefinitionException ('References not supported for virtual attributes ' );
@@ -279,10 +275,8 @@ protected function resolveProperty(
279275 $ relation ->asSelfReference ();
280276 }
281277 $ this ->relations [$ property ->getName ()] = $ relation ;
282- if (!$ property ->isRefPointerToSelf ()) {
283- $ this ->addInverseRelation ($ relatedClassName , $ attribute , $ property , $ fkProperty );
284- }
285278 }
279+
286280 if (!$ property ->isReference () && !$ property ->hasRefItems ()) {
287281 [$ min , $ max ] = $ property ->guessMinMax ();
288282 $ attribute ->setIsVirtual ($ property ->isVirtual ())
@@ -338,6 +332,7 @@ protected function resolveProperty(
338332 ->asHasMany ([$ foreignPk => $ this ->componentSchema ->getPkName ()]);
339333 return ;
340334 }
335+
341336 $ relatedClassName = $ property ->getRefClassName ();
342337 $ relatedTableName = $ property ->getRefSchema ()->resolveTableName ($ relatedClassName );
343338 if ($ this ->catchManyToMany (
@@ -518,22 +513,4 @@ public static function relationName(string $propertyName, ?string $fkColumnName)
518513 }
519514 return $ relationName ;
520515 }
521-
522- /**
523- * @throws InvalidConfigException
524- */
525- public function addInverseRelation (
526- string $ relatedClassName ,
527- Attribute $ attribute ,
528- PropertySchema $ property ,
529- PropertySchema $ fkProperty
530- ): void {
531- $ inverseRelation = Yii::createObject (
532- AttributeRelation::class,
533- [$ this ->schemaName , $ this ->tableName , $ this ->schemaName ]
534- )
535- ->asHasOne ([$ attribute ->columnName => $ fkProperty ->getName ()]);
536- $ inverseRelation ->setInverse ($ property ->getName ());
537- $ this ->inverseRelations [$ relatedClassName ][] = $ inverseRelation ;
538- }
539516}
0 commit comments