【问题标题】:Symfony 2 manyToMany clashing mapping table namesSymfony 2 manyToMany 冲突映射表名称
【发布时间】:2013-12-04 09:15:37
【问题描述】:

我想向促销实体添加独家/包容性产品。 尝试生成映射表时名称冲突。

喜欢:

两个表的promotion_product

promotion.orm.yml

manyToMany:
    productsIncluded:
        targetEntity: Acme\Bundle\DemoBundle\Entity\Product
    productsExcluded:
        targetEntity: Acme\Bundle\DemoBundle\Entity\Product

我猜这是可以实现的,但是有这样的东西:

manyToMany:
    productsIncluded:
        targetEntity: Acme\Bundle\DemoBundle\Entity\Product
        joinTable:
            name: promotion_included_product
            joinColumns:
                promotion_id:
                referencedColumnName: id
            inverseJoinColumns:
                product_id:
                referencedColumnName: id
    productsExcluded:
        targetEntity: Acme\Bundle\DemoBundle\Entity\Product
        joinTable:
            name: promotion_excluded_product
            joinColumns:
                promotion_id:
                referencedColumnName: id
            inverseJoinColumns:
                product_id:
                referencedColumnName: id

这是一种方式吗?还是 symfony auto 有更简单/更简洁的方式来处理这个问题?

告诉我谢谢。

【问题讨论】:

    标签: php symfony doctrine-orm many-to-many


    【解决方案1】:

    就是这样,虽然 joinColumns 和 inverseJoinColumns 默认值应该与您键入的相同,因此您可以将其缩短为:

    manyToMany:
        productsIncluded:
            targetEntity: Acme\Bundle\DemoBundle\Entity\Product
            joinTable:
                name: promotion_included_product
        productsExcluded:
            targetEntity: Acme\Bundle\DemoBundle\Entity\Product
            joinTable:
                name: promotion_excluded_product
    

    【讨论】:

    • 是的,我之前也尝试过,但是没有用。给出错误提示 [Symfony\Component\Debug\Exception\ContextErrorException] 注意:未定义索引:joinColumns。这是我去定义连接列的时候。我想没有其他更干净的紧凑版本:D
    • 嗯,很奇怪,我希望它像使用注释映射时一样使用默认值,但看起来他们没有处理:)
    • 好吧,我也是这么想的,但我想可能还有更多的东西......:D
    猜你喜欢
    • 1970-01-01
    • 2012-10-15
    • 2012-04-30
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2017-10-31
    • 2023-02-10
    • 2013-04-24
    相关资源
    最近更新 更多