cakephp – 配置蛋糕烘焙以启用级联删除

我正在使用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',//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来查看cake bake model选项的帮助

$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

相关文章

统一支付是JSAPI/NATIVE/APP各种支付场景下生成支付订单,返...
统一支付是JSAPI/NATIVE/APP各种支付场景下生成支付订单,返...
前言 之前做了微信登录,所以总结一下微信授权登录并获取用户...
FastAdmin是我第一个接触的后台管理系统框架。FastAdmin是一...
之前公司需要一个内部的通讯软件,就叫我做一个。通讯软件嘛...
统一支付是JSAPI/NATIVE/APP各种支付场景下生成支付订单,返...