From d29544afa2fdce7c6d476792a1477fb6c97fe00f Mon Sep 17 00:00:00 2001 From: Luiz Marin <67489841+luizcmarin@users.noreply.github.com> Date: Sat, 23 Nov 2024 19:54:57 -0300 Subject: [PATCH] Update ModelCommand.php --- src/Command/ModelCommand.php | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-) diff --git a/src/Command/ModelCommand.php b/src/Command/ModelCommand.php index 78f891c3..f90b48e5 100644 --- a/src/Command/ModelCommand.php +++ b/src/Command/ModelCommand.php @@ -1,4 +1,5 @@ $tmpModelName, + 'className' => $tmpModelName, 'foreignKey' => $fieldName, ]; if ($schema->getColumn($fieldName)['null'] === false) { $assoc['joinType'] = 'INNER'; } } - 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; } @@ -711,7 +716,7 @@ public function getEntityPropertySchema(Table $model): array if ($entityClass === '\Cake\ORM\Entity') { $namespace = Configure::read('App.namespace'); - [$plugin, ] = pluginSplit($association->getTarget()->getRegistryAlias()); + [$plugin,] = pluginSplit($association->getTarget()->getRegistryAlias()); if ($plugin !== null) { $namespace = $plugin; } @@ -1355,7 +1360,7 @@ public function buildOptionParser(ConsoleOptionParser $parser): ConsoleOptionPar ])->addOption('skip-relation-check', [ 'boolean' => true, 'help' => 'Generate relations for all "example_id" fields' - . ' without checking the database if a table "examples" exists.', + . ' without checking the database if a table "examples" exists.', ])->setEpilog( 'Omitting all arguments and options will list the table names you can generate models for.' );