Symfony 2 manyToMany映射表名称冲突


Symfony 2 manyToMany clashing mapping table names

我想向促销实体添加排他性/包容性产品。当它试图生成映射表时,名称会发生冲突。

类似:

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处理这个问题?

让我知道谢谢。

就是这样,尽管joinColumns和inverteJoinColumns的默认值应该与您键入的相同,所以您可以将其缩短为:

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