Reputation: 81
I have two entities, Match and Team, problem is in mapping (i guess), i am not looking for someone to give me solution to this problem, just give me some hint where should i look in documentation. For some reason i got stuck on this and can't find solution.. I will provide code of my two entities. Match.php
/**
* @var
* @ORM\ManyToOne(targetEntity="AppBundle\Entity\Team", inversedBy="matchOne")
* @ORM\JoinColumn(name="team_one_id", referencedColumnName="id")
*/
protected $teamOne;
/**
* @var
* @ORM\ManyToOne(targetEntity="AppBundle\Entity\Team", inversedBy="matchTwo")
* @ORM\JoinColumn(name="team_two_id", referencedColumnName="id")
*/
protected $teamTwo;
Team.php
/**
* @var
* @ORM\OneToMany(targetEntity="AppBundle\Entity\Match", mappedBy="teamOne")
*/
protected $matchOne;
/**
* @var
* @ORM\OneToMany(targetEntity="AppBundle\Entity\Match", mappedBy="teamTwo")
*/
protected $matchTwo;
Problem is in my form type when i query for match, here is part of code
->add('match', EntityType::class, [
'class' => 'AppBundle:Match',
'choice_label' => 'getMatch',
] )
And getMatch function
public function getMatch() {
return $this->getTeamOne()->getName() . ' - ' . $this->getTeamTwo()->getName();
}
Form type is for creating new bet, obviously i want to show matches (team names, example: Chelsea - Liverpool) in drop down and write id of that match to bet entity.
Upvotes: 0
Views: 326
Reputation: 81
Problem was in table name. Match is reserved word in MySQL. So everyone who experience same or similar problem please first check if your table names might be reserved word. I lost one whole day on this and every time i have some problem like this it is something stupid like this...
Upvotes: 1