I want to do mapping that does this:
User can own multiple Games. Games can have multiple owners.
I have id column in game table and game and user columns in ownership table. How I can connect these fields? I want to have game and user fields in ownership related to user and game tables.
I tried OneToMany and ManyToMany, but the first one results in generating additional columns. I don’t want to insert anything in game table.
–edit–
My @ManyToMany code:
/**
* @ORM\ManyToMany(targetEntity="Ownership")
* @ORM\JoinTable(name="ownership",
* joinColumns={JoinColumn(name="user", referencedColumnName="id")},
* inverseJoinColumns={JoinColumn(name="game", referencedColumnName="id")}
* )
*/
It causes an error in Symfony’s command line:
[Doctrine\Common\Annotations\AnnotationException]
[Semantical Error] Couldn't find constant JoinColumn, property GameShelf\Us
ersBundle\Entity\User::$ownership.
Of course you need many to many relations if, like you said:
The Doctrine should create third table (which could contains only two foreign keys: game_id and ownership_id).
The error is caused because Doctrine dosen’t know what
JoinColumnis. You just did wrong annotation because you forgot (again! ;)) precedeJoinColumnwith `@ORM. The right annotation should look like this: