gpt4 book ai didi

cakephp - 配置 cake bake 以启用级联删除

转载 作者:行者123 更新时间:2023-12-04 08:54:45 24 4
gpt4 key购买 nike

我正在使用 cakephp v3.3.3

在使用 cake bake 自动生成代码后,我有这个 php 文件 BallsTable.php,它有下面的 initialize() 函数;

public function initialize(array $config)
{
parent::initialize($config);

$this->table('balls');
$this->displayField('id');
$this->primaryKey('id');

$this->belongsTo('Baskets', [
'foreignKey' => 'basket_id',
'joinType' => 'INNER'
]);
$this->hasMany('BallRecords', [
'foreignKey' => 'ball_id',
]);
}

但是,上面的 initialize() 函数不允许我进行级联删除。

我需要像下面那样手动修改 initialize() 以启用级联删除。但这很麻烦,因为每次烘烤新蛋糕时文件都会被覆盖。
    $this->hasMany('BallRecords', [
'foreignKey' => 'ball_id',
//http://book.cakephp.org/3.0/en/orm/deleting-data.html
//manually add the 2 lines below to enable cascading delete
'dependent' => true,
'cascadeCallbacks' => true,
]);

是否有某种方法可以将蛋糕烘焙配置为自动生成手动启用级联删除的代码?

编辑:添加了一个赏金来邀请配置烘焙模板的答案。

最佳答案

抱歉不行...
从 Cake Back Model 生成器,您可以配置与 Cascading 选项的关联。
您可以通过输入命令 bin/cake bake model --help 在蛋糕烘焙模型选项的帮助下进行检查

$ bin/cake bake model --help

Welcome to CakePHP v3.3.3 Console
---------------------------------------------------------------
App : src
Path: C:\wamp\www\student_logic\src\
PHP : 5.5.12
---------------------------------------------------------------
Bake table and entity classes.

Usage:
cake bake.bake model [subcommand] [options] [<name>]

Subcommands:

all Bake all model files with associations and validation.

To see help on a subcommand use `cake bake.bake model [subcommand] --help`

Options:

--help, -h Display this help.
--verbose, -v Enable verbose output.
--quiet, -q Enable quiet output.
--plugin, -p Plugin to bake into.
--force, -f Force overwriting existing files without
prompting.
--connection, -c The datasource connection to get data from.
(default: default)
--theme, -t The theme to use when baking code.
(choices: Bake|Migrations)
--table The table name to use if you have
non-conventional table names.
--no-entity Disable generating an entity class.
--no-table Disable generating a table class.
--no-validation Disable generating validation rules.
--no-rules Disable generating a rules checker.
--no-associations Disable generating associations.
--no-fields Disable generating accessible fields in the
entity.
--fields A comma separated list of fields to make
accessible.
--no-hidden Disable generating hidden fields in the entity.
--hidden A comma separated list of fields to hide.
--primary-key The primary key if you would like to manually set
one. Can be a comma separated list if you are
using a composite primary key.
--display-field The displayField if you would like to choose one.
--no-test Do not generate a test case skeleton.
--no-fixture Do not generate a test fixture skeleton.

Arguments:

name Name of the model to bake. Can use Plugin.name to bake plugin
models. (optional)

Omitting all arguments and options will list the table names you can
generate models for

关于cakephp - 配置 cake bake 以启用级联删除,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/39383929/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com