Symfony 2 manyToMany冲突映射表名

时间:2013-12-04 09:15:38

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

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

像:

两个表的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自动处理这种方式更简单/更清洁?

让我知道谢谢。

1 个答案:

答案 0 :(得分: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