From 86e538255d7f3065f1fc74fc3cfc0bd73d8ec3b5 Mon Sep 17 00:00:00 2001 From: Luiz Marin <67489841+luizcmarin@users.noreply.github.com> Date: Tue, 26 Nov 2024 11:22:02 -0300 Subject: [PATCH] Update ModelCommand.php correction due to the error shown below. Creating file C:\marin\www\GitHub\lixo\tests\TestCase\Model\Table\AnnouncementsTableTest.php Wrote `C:\marin\www\GitHub\lixo\tests\TestCase\Model\Table\AnnouncementsTableTest.php` Done One moment while associations are detected. 2024-11-26 10:24:32 warning: Undefined variable $className Trace: Bake\Command\ModelCommand->findBelongsTo() C:\marin\www\GitHub\trash\vendor\cakephp\bake\src\Command\ModelCommand.php, line 247 Bake\Command\ModelCommand->getAssociations() C:\marin\www\GitHub\trash\vendor\cakephp\bake\src\Command\ModelCommand.php, line 166 Bake\Command\ModelCommand->getTableContext() C:\marin\www\GitHub\trash\vendor\cakephp\bake\src\Command\ModelCommand.php, line 119 Bake\Command\ModelCommand->bake() C:\marin\www\GitHub\lixo\vendor\cakephp\bake\src\Command\ModelCommand.php, line 101 Bake\Command\ModelCommand->execute() C:\marin\www\GitHub\trash\vendor\cakephp\bake\src\Command\AllCommand.php, line 116 Bake\Command\AllCommand->execute() C:\marin\www\GitHub\trash\vendor\cakephp\cakephp\src\Console\BaseCommand.php, line 204 Cake\Console\BaseCommand->run() C:\marin\www\GitHub\trash\vendor\cakephp\cakephp\src\Console\CommandRunner.php, line 330 Cake\Console\CommandRunner->runCommand() C:\marin\www\GitHub\trash\vendor\cakephp\cakephp\src\Console\CommandRunner.php, line 168 Cake\Console\CommandRunner->run() C:\marin\www\GitHub\lixo\bin\cake.php, line 10 [main] --- src/Command/ModelCommand.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Command/ModelCommand.php b/src/Command/ModelCommand.php index 05f46112..6ae80550 100644 --- a/src/Command/ModelCommand.php +++ b/src/Command/ModelCommand.php @@ -346,6 +346,7 @@ public function getAssociationInfo(Table $table): array */ public function findBelongsTo(Table $model, array $associations, ?Arguments $args = null): array { + $className = null; $schema = $model->getSchema(); foreach ($schema->columns() as $fieldName) { if (!preg_match('/^.+_id$/', $fieldName) || ($schema->getPrimaryKey() === [$fieldName])) { @@ -377,7 +378,6 @@ public function findBelongsTo(Table $model, array $associations, ?Arguments $arg ) { $allowAliasRelations = $args && $args->getOption('skip-relation-check'); $found = $this->findTableReferencedBy($schema, $fieldName); - $className = null; if ($found) { $className = ($this->plugin ? $this->plugin . '.' : '') . Inflector::camelize($found); } elseif (!$allowAliasRelations) {