A
A
Alexander2015-09-15 18:49:41
Doctrine ORM
Alexander, 2015-09-15 18:49:41

Trait categories in Doctrine and symfony2, what about DiscriminatorColumn?

I want to make a category trait that I will use in several Entities. I can not find how to resolve the Discriminator.
Source at the moment:

Trait CollectionTrait
{
    /**
     * @ORM\ManyToMany(targetEntity="DesignerBundle\Entity\Collection")
     * @ORM\JoinTable(
     *      name="entities_to_collections",
     *      joinColumns={@ORM\JoinColumn(name="entity_id", referencedColumnName="id")},
     *      inverseJoinColumns={@ORM\JoinColumn(name="collection_id", referencedColumnName="id")}
     * )
     */
    protected $collections;
    ...........
    ...........
}

Naturally, this does not work, it gives the error "The table with name 'entities_to_collections' already exists."
I would be very grateful for your help :)

Answer the question

In order to leave comments, you need to log in

1 answer(s)
Q
Quber, 2017-11-08
@Quber

Trait CollectionTrait
{
    /**
     * @ORM\ManyToMany(targetEntity="DesignerBundle\Entity\Collection")
     * @ORM\JoinTable(
     *      joinColumns={@ORM\JoinColumn(referencedColumnName="id")},
     *      inverseJoinColumns={@ORM\JoinColumn(referencedColumnName="id")}
     * )
     */
    protected $collections;
    ...........
    ...........
}

Write like this, the doctrine will do the rest automatically: it will assign the table name and column names.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question