CakePHP 3删除特定的关联数据

时间:2015-03-27 16:14:34

标签: cakephp-3.0

有没有办法删除Cake 3中的某些特定关联数据?

例如在博客示例中,我想删除标记" important"从帖子3?

1 个答案:

答案 0 :(得分:3)

您可以使用关联类中的方法删除一个实体与另一个实体之间的链接:

$post = ... // Fetch the post that contains the tag
$tag = $this->Posts->Tags->get($this->request->data('tag_to_delete'));
$this->Posts->Tags->unlink($post, [$tag]);