开发者

Doctrine 2.0 entity with relations - delete record

开发者 https://www.devze.com 2023-02-22 08:08 出处:网络
When I delete record from Entity with relations (@onetoone or @onetomany) All relations records will deleted too

When I delete record from Entity with relations (@onetoone or @onetomany)

All relations records will deleted too

    $em = $this->getEm();
    $post = $em->find('Blog\\WebBundle\\Entity\\Posts', $pid);
    // not found
    if (!$post) {
        throw ExceptionController::notFound('The post does not ex开发者_StackOverflowist.');
    }
    $em->remove($post);
    $em->flush();

    return $this->redirectGenerate('_posts');

For example this code, remove user, that create post too, because between posts and users there is a relations

How to avoid this?

0

精彩评论

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