I am a begginer in Doctrine and i am stuck in kind of a loop trying to establish a join table between 2 entities.
I have a relation OneToMany between a "train" and "containers" and ManyToOne between "containers" and "train" obviously.
I placed annotations on the OneToMany relation like this :
@ORM\Entity/Train
@ORM\OneToMany(targetEntity=Container::class, mappedBy="Train")
@ORM\JoinTable(name="train_container",
@ORM\joinColumns={@JoinColumn(name="id_tm", referencedColumnName="id_tm", nullable=false)},
@ORM\inverseJoinColumns={@JoinColumn(name="id_container", referencedColumnName="id_container", nullable=false)})
)
private $Container;
and on the ManyToOne i did like this :
@ORM\Entity/Container
@ORM\ManyToOne(targetEntity=Train::class, inversedBy="Containers")
@ORM\JoinColumn(name="id_tm", referencedColumnName="id_tm")
private $Train;
Now, if i let it like that, i have an error saying :
Annotation @ORM\joinColumns is not allowed to be declared on property App\Entity\Train::$container. You may only use this annotation on these code elements: PROPERTY.
If i remove the joinColumn and just put this :
@ORM\ManyToOne(targetEntity=Train::class, inversedBy="Container")
private $Train;
I have this error :
Could not resolve type of column "id" of class "App\Entity\Train"
I have no idea why its displaying an "id" column because the name of the column and the property on "Train" is always "id_tm" everywhere.
Could anyone tell me what i am doing wrong please ?
thanks a lot in advance M
edit to add the code on the id's properties :
@ORM\Id
@ORM\GeneratedValue
@ORM\Column(type="integer", name="id_container")
private $id_container;
@ORM\Id
@ORM\GeneratedValue
@ORM\Column(type="integer", name="id_train")
private $id_train;