Skip to content

Commit

Permalink
Update ModelCommand.php
Browse files Browse the repository at this point in the history
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]
  • Loading branch information
luizcmarin authored Nov 26, 2024
1 parent ac33316 commit 86e5382
Showing 1 changed file with 1 addition and 1 deletion.
2 changes: 1 addition & 1 deletion src/Command/ModelCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -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])) {
Expand Down Expand Up @@ -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) {
Expand Down

0 comments on commit 86e5382

Please sign in to comment.