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)
精彩评论