I have the following tables in my ERM/database:
card, expansion and card_expansionManyToMany
-Relationship between card and expansion. A card can be in many expansions and an expansion can hold a many of cards.
collection
Description of how many cards from which expansion are needed. Card A from Expansion B is needed 3 times. So there's a OneToMany
relationship to card_expansion
.
I want to map these relations in my Entities-objects using Doctrine. Mapping between cards and expansions is no problem.
But since the card_expansion
table isn't mapped directly by an entity, I don't have a clue how to access it from my Collection
entity or which annotation I have to use to build up that connection correctly...
What do I need to map to get this working?
Here's the code of my Expansion
entity:
/**
* @Entity
* @Table(name="expansion")
*/
class Expansion {
...
/**
* @ManyToMany(targetEntity="Card")
* @JoinTable(name="card_expansion",
* joinColumns={@JoinColumn(name="_expansion", referencedColumnName="id")},
* inverseJoinColumns={@JoinColumn(name="_card", referencedColumnName="id", unique=true)})
*/
private $cards;
public function __construct () {
$this->cards = new ArrayCollection();
}
and here's my Collection
Entity
/**
* @Entity
* @Table(name="collection")
*/
class Collection{
/**
* @OneToMany(targetEntity="???")
* @JoinTable(name="card_in_expansion")
*/
private $card_in_expansion;