将 onDelete 与原则 2 一起使用

发布于 2024-12-18 13:36:56 字数 472 浏览 4 评论 0原文

我无法让 onDelete 在 Doctrine2 中工作(使用 YAML 映射)。

我在我的 Product 类中尝试了这种关系:

oneToOne:
    category:
      targetEntity: Category
      onDelete: CASCADE

但这不起作用..

编辑:

的数据库中手动设置 ON DELETE: CASCADE

我已在导入 YAML 映射 使用doctrine:mapping:import

清空数据库,

使用doctrine:schema:update从架构中更新它,并且在外部没有ON DELETE关键..看起来如此就像甚至 Doctrine 都不知道该怎么做,哈哈..

I can't get the onDelete to work in Doctrine2 (with YAML Mapping).

I tried this relation in my Product class:

oneToOne:
    category:
      targetEntity: Category
      onDelete: CASCADE

But that doesn't work..

EDIT:

I've set the ON DELETE: CASCADE manually in the database

imported the YAML mapping with doctrine:mapping:import,

emptied the database

updated it from the schema with doctrine:schema:update and got no ON DELETE in the foreign key.. so looks like even Doctrine doesn't know how to do it lol..

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

风轻花落早 2024-12-25 13:36:56

好的,明白了!我必须在 joinColumn 内使用 onDelete

oneToOne:
    category:
        targetEntity: Category
        joinColumn:
            onDelete: CASCADE

OK, got it! I had to use onDelete inside joinColumn:

oneToOne:
    category:
        targetEntity: Category
        joinColumn:
            onDelete: CASCADE
空心↖ 2024-12-25 13:36:56

这是joinTable中使用onDelete的方法:

manyToMany:
    parameters:
        targetEntity: Fox\LandingBundle\Entity\Parameter
        cascade: ["persist","remove"]
        joinTable:
            name: subscriberBox_parameter
            joinColumns:
                subscriberBox_id:
                    referencedColumnName: id
            inverseJoinColumns:
                parameter_id:
                    referencedColumnName: id
                    onDelete: CASCADE

This is the way to use onDelete in joinTable:

manyToMany:
    parameters:
        targetEntity: Fox\LandingBundle\Entity\Parameter
        cascade: ["persist","remove"]
        joinTable:
            name: subscriberBox_parameter
            joinColumns:
                subscriberBox_id:
                    referencedColumnName: id
            inverseJoinColumns:
                parameter_id:
                    referencedColumnName: id
                    onDelete: CASCADE
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文