Skip to content

Commit

Permalink
Update ModelCommand.php
Browse files Browse the repository at this point in the history
  • Loading branch information
luizcmarin committed Nov 23, 2024
1 parent 9f1f6f3 commit d29544a
Showing 1 changed file with 8 additions and 3 deletions.
11 changes: 8 additions & 3 deletions src/Command/ModelCommand.php
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
<?php

declare(strict_types=1);

Check failure on line 3 in src/Command/ModelCommand.php

View workflow job for this annotation

GitHub Actions / cs-stan / Coding Standard & Static Analysis

Expected 0 lines before declare statement, found 1.

/**
Expand All @@ -14,6 +15,7 @@
* @since 0.1.0
* @license https://www.opensource.org/licenses/mit-license.php MIT License
*/

namespace Bake\Command;

use Bake\CodeGen\FileBuilder;
Expand Down Expand Up @@ -385,16 +387,19 @@ public function findBelongsTo(Table $model, array $associations, ?Arguments $arg
}
$assoc = [
'alias' => $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;

Check failure on line 401 in src/Command/ModelCommand.php

View workflow job for this annotation

GitHub Actions / cs-stan / Coding Standard & Static Analysis

Double space found
}
$associations['belongsTo'][] = $assoc;
}

Expand Down Expand Up @@ -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;
}
Expand Down Expand Up @@ -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.'
);
Expand Down

0 comments on commit d29544a

Please sign in to comment.