Description
Hi,
this issue is a follow up of #1059. Currently it is not possible to ignore any Association is already set errors when baking models. In my case I have a Systems table with an system_id. The baking logic is creating an association to itself, which results into the error message.
Steps to reproduce:
bin/cake bake migration CreateSystems system_id:string created modified
bin/cake migrations migrate
bin/cake bake all systems
I think it is Ok to print this out as a warning. How ever in my case system_id is not a foreign key, it's an ID provided by another system. My workaround for this was, to temporarily rename the column.
mysql> alter table `systems` rename column `system_id` to `herbert_id`;
mysql> \! bin/cake bake all systems
mysql> alter table `systems` rename column `herbert_id` to `system_id`;
While this is maybe an edge case, I think we should keep the power by the developer. If bake detects something sketchy, print a warning. That's fine. The CakeException should only be thrown at runtime.
Error:
/var/www/html # bin/cake bake all systems
Bake All
-------------------------------------------------------------------------------
One moment while associations are detected.
2026-06-15 10:06:54 error: [Cake\Core\Exception\CakeException] Association alias `Systems` is already set. in /var/www/html/vendor/cakephp/cakephp/src/ORM/AssociationCollection.php on line 84
Stack Trace:
- CORE/src/ORM/AssociationCollection.php:110
- CORE/src/ORM/Table.php:1140
- ROOT/vendor/cakephp/bake/src/Command/ModelCommand.php:281
- ROOT/vendor/cakephp/bake/src/Command/ModelCommand.php:163
- ROOT/vendor/cakephp/bake/src/Command/ModelCommand.php:115
- ROOT/vendor/cakephp/bake/src/Command/ModelCommand.php:97
- ROOT/vendor/cakephp/bake/src/Command/AllCommand.php:120
- CORE/src/Console/BaseCommand.php:258
- CORE/src/Console/CommandRunner.php:375
- CORE/src/Console/CommandRunner.php:193
- ROOT/bin/cake.php:10
- [main]:
CakePHP version: 5.3.6
Description
Hi,
this issue is a follow up of #1059. Currently it is not possible to ignore any
Association is already seterrors when baking models. In my case I have aSystemstable with ansystem_id. The baking logic is creating an association to itself, which results into the error message.Steps to reproduce:
I think it is Ok to print this out as a warning. How ever in my case
system_idis not a foreign key, it's an ID provided by another system. My workaround for this was, to temporarily rename the column.While this is maybe an edge case, I think we should keep the power by the developer. If
bakedetects something sketchy, print a warning. That's fine. TheCakeExceptionshould only be thrown at runtime.Error:
CakePHP version: 5.3.6