diff --git a/src/Command/ModelCommand.php b/src/Command/ModelCommand.php index 423f088e..e87bc4ef 100644 --- a/src/Command/ModelCommand.php +++ b/src/Command/ModelCommand.php @@ -382,6 +382,7 @@ public function findBelongsTo(Table $model, array $associations, ?Arguments $arg } $assoc = [ 'alias' => $tmpModelName, + 'className' => $tmpModelName, 'foreignKey' => $fieldName, ]; if ($schema->getColumn($fieldName)['null'] === false) { @@ -392,6 +393,9 @@ public function findBelongsTo(Table $model, array $associations, ?Arguments $arg if ($this->plugin && empty($assoc['className'])) { $assoc['className'] = $this->plugin . '.' . $assoc['alias']; } + if (!empty($assoc['className'])) { + $assoc['alias'] = $assoc['className'] . '_' . $model->getAlias() . '_' . $fieldName; + } $associations['belongsTo'][] = $assoc; }