开发者

CakePHP recursive delete

There are posts and comments table.

For one post th开发者_开发百科ere are multiple comments.

If i delete one post will the comments for that post be automatically deleted in cakephp ?


var $hasMany = array(
  'Comment' => array(
     'className' => 'Comment',
     'foreignKey' => 'post_id',
     'dependent'=> true
   )
); 


This really shouldn't be up to CakePHP... let your database handle that by using FOREIGN KEY constraints and set it to ON DELETE CASCADE


If you are using the foreign key Constraint ON DELETE CASCADE, yes.

See here for documentation (works with engine InnoDB)

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜