CakePHP - delete cascade not working

前端 未结 3 992
小鲜肉
小鲜肉 2021-01-06 13:50

In CakePHP I have a model Type and SpecificType.

SpecificType belongTo a Type. (type_id field)

When I delete an entry of SpecificType, how can I also delet

3条回答
  •  南方客
    南方客 (楼主)
    2021-01-06 14:30

    I don't think you can delete Type with SpecificType cascade. you can only use cascade if there's hasMany or HABTM relation.

    it is said in the manual.

    Deletes the record identified by $id. By default, also deletes records dependent on the record specified to be deleted.

    For example, when deleting a User record that is tied to many Recipe records (User 'hasMany' or 'hasAndBelongsToMany' Recipes):

    * if $cascade is set to true, the related Recipe records are also
    

    deleted if the models dependent-value is set to true. * if $cascade is set to false, the Recipe records will remain after the User has been deleted.

    you can always run

    $this->del($id, true);
    

    to remove your Type with related SpecificType-s.

提交回复
热议问题