Skip to content

Commit 1231531

Browse files
committed
Refactor 2
1 parent 2eda480 commit 1231531

File tree

4 files changed

+0
-53
lines changed

4 files changed

+0
-53
lines changed

src/generator/default/dbmodel.php

-8
Original file line numberDiff line numberDiff line change
@@ -144,12 +144,4 @@ public function get<?= $relation->getCamelName() ?>()
144144
<?php endif;?>
145145
}
146146
<?php endforeach; ?>
147-
<?php $i = 1; foreach ($model->inverseRelations as $relationName => $relation): ?>
148-
149-
public function get<?= $relation->getCamelName().($i===1 ? '' : $i) ?>()
150-
{
151-
return $this-><?= $relation->getMethod() ?>(\<?= trim($relationNamespace, '\\') ?>\<?= $relation->getClassName() ?>::class, <?php
152-
echo $relation->linkToString() ?>)->inverseOf('<?= $relation->getInverse() ?>');
153-
}
154-
<?php $i++; endforeach; ?>
155147
}

src/lib/AttributeResolver.php

-29
Original file line numberDiff line numberDiff line change
@@ -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;
@@ -336,12 +331,6 @@ protected function resolveProperty(
336331
)
337332
->asHasMany([$foreignPk => $this->componentSchema->getPkName()]);
338333
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-
}
345334
}
346335

347336
$relatedClassName = $property->getRefClassName();
@@ -524,22 +513,4 @@ public static function relationName(string $propertyName, ?string $fkColumnName)
524513
}
525514
return $relationName;
526515
}
527-
528-
/**
529-
* @throws InvalidConfigException
530-
*/
531-
public function addInverseRelation(
532-
string $relatedClassName,
533-
Attribute $attribute,
534-
PropertySchema $property,
535-
PropertySchema $fkProperty
536-
): void {
537-
$inverseRelation = Yii::createObject(
538-
AttributeRelation::class,
539-
[$this->schemaName, $this->tableName, $this->schemaName]
540-
)
541-
->asHasOne([$attribute->columnName => $fkProperty->getName()]);
542-
$inverseRelation->setInverse($property->getName());
543-
$this->inverseRelations[$relatedClassName][] = $inverseRelation;
544-
}
545516
}

src/lib/SchemaToDatabase.php

-11
Original file line numberDiff line numberDiff line change
@@ -106,21 +106,10 @@ public function prepareModels(): array
106106
/** @var AttributeResolver $resolver */
107107
$resolver = Yii::createObject(AttributeResolver::class, [$schemaName, $schema, $junctions, $this->config]);
108108

109-
// $models[$schemaName] = $resolver->resolve();
110109
$resolvers[$schemaName] = $resolver;
111110
$models[$schemaName] = $resolvers[$schemaName]->resolve();
112111
}
113112

114-
// handle inverse relation
115-
foreach ($resolvers as $aResolver) {
116-
foreach ($aResolver->inverseRelations as $name => $relations) {
117-
foreach ($relations as $relation) {
118-
/** @var AttributeRelation $relation */
119-
$models[$name]->inverseRelations[] = $relation;
120-
}
121-
}
122-
}
123-
124113
foreach ($models as $model) {
125114
foreach ($model->many2many as $relation) {
126115
if (isset($models[$relation->viaModelName])) {

src/lib/items/DbModel.php

-5
Original file line numberDiff line numberDiff line change
@@ -67,11 +67,6 @@ class DbModel extends BaseObject
6767
*/
6868
public array $many2many = [];
6969

70-
/**
71-
* @var array|AttributeRelation[] inverse relations
72-
*/
73-
public array $inverseRelations = [];
74-
7570
public array $junctionCols = [];
7671

7772
/**

0 commit comments

Comments
 (0)