Chathushka
Chathushka

Reputation: 445

Symfony 2 manyToMany clashing mapping table names

I want to to add exclusive/inclusive products to promotion entity. There is a clash of names when it tries to generate mapping table.

like:

promotion_product for both tables

promotion.orm.yml

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

I am guessing that this can be achieved but having something like this:

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

Is this a way?, or is there an easier/cleaner way that symfony auto handles this?

Let me know thanks.

Upvotes: 0

Views: 435

Answers (1)

Igor Pantović
Igor Pantović

Reputation: 9246

That's the way, although joinColumns and inverseJoinColumns defaults should be the same as you typed so you could shorten it to:

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

Upvotes: 1

Related Questions