From 730f6c3a17540cf15229150af03a4418d5db9a24 Mon Sep 17 00:00:00 2001 From: ADmad Date: Tue, 15 Jul 2025 07:36:38 +0530 Subject: [PATCH] Ensure fallback class is enabled for the table locator. It's recommended to disable fallback class during normal functioning of the app but fallback needs to be enabled when baking as the required table classes might still not have been created. --- src/Command/BakeCommand.php | 17 +++++++++++++++++ src/Command/TemplateCommand.php | 2 ++ 2 files changed, 19 insertions(+) diff --git a/src/Command/BakeCommand.php b/src/Command/BakeCommand.php index 930ac6b9..c55f2f5a 100644 --- a/src/Command/BakeCommand.php +++ b/src/Command/BakeCommand.php @@ -27,6 +27,7 @@ use Cake\Core\ConventionsTrait; use Cake\Event\Event; use Cake\Event\EventManager; +use Cake\ORM\Locator\TableLocator; use InvalidArgumentException; use function Cake\Core\pluginSplit; @@ -48,6 +49,22 @@ abstract class BakeCommand extends Command */ protected string $pathFragment; + /** + * Initialize the command. + * + * @return void + */ + public function initialize(): void + { + parent::initialize(); + + $locator = $this->getTableLocator(); + if ($locator instanceof TableLocator) { + $locator->allowFallbackClass(true); + $this->setTableLocator($locator); + } + } + /** * Get the command name. * diff --git a/src/Command/TemplateCommand.php b/src/Command/TemplateCommand.php index 558187ab..b5868a0a 100644 --- a/src/Command/TemplateCommand.php +++ b/src/Command/TemplateCommand.php @@ -100,6 +100,8 @@ class TemplateCommand extends BakeCommand */ public function initialize(): void { + parent::initialize(); + $this->path = current(App::path('templates')); }