Reputation: 1339
here an entity :
namespace Siriru\GSBundle\Entity;
use Doctrine\ORM\Mapping as ORM;
/**
* @ORM\Entity
* @ORM\Table(name="match")
*/
class Match
{
/**
* @ORM\Column(type="integer")
* @ORM\Id
* @ORM\GeneratedValue(strategy="AUTO")
*/
protected $id;
/**
* @ORM\Column(type="integer")
*/
protected $step;
/**
* @ORM\ManyToOne(targetEntity="Siriru\GSBundle\Entity\Player")
*/
protected $player1;
/**
* @ORM\ManyToOne(targetEntity="Siriru\GSBundle\Entity\Player")
* @ORM\JoinColumn(nullable=true)
*/
protected $player2;
/**
* @ORM\Column(type="time", nullable=true)
*/
protected $time1;
/**
* @ORM\Column(type="time", nullable=true)
*/
protected $time2;
/**
* @ORM\ManyToOne(targetEntity="Siriru\GSBundle\Entity\Player")
* @ORM\JoinColumn(nullable=true)
*/
protected $winner;
/**
* @ORM\ManyToOne(targetEntity="Siriru\GSBundle\Entity\GoldsprintType", inversedBy="matches")
* @ORM\JoinColumn(nullable=false)
*/
protected $type;
/**
* Constructor
*/
public function __construct(Player $player1, Player $player2 = null)
{
$this->player1 = $player1;
$this->player2 = $player2;
}
/**
* Get id
*
* @return integer
*/
public function getId()
{
return $this->id;
}
/**
* Set step
*
* @param integer $step
* @return Match
*/
public function setStep($step)
{
$this->step = $step;
return $this;
}
/**
* Get step
*
* @return integer
*/
public function getStep()
{
return $this->step;
}
/**
* Set time1
*
* @param \DateTime $time1
* @return Match
*/
public function setTime1($time1 = null)
{
$this->time1 = $time1;
return $this;
}
/**
* Get time1
*
* @return \DateTime
*/
public function getTime1()
{
return $this->time1;
}
/**
* Set time2
*
* @param \DateTime $time2
* @return Match
*/
public function setTime2($time2 = null)
{
$this->time2 = $time2;
return $this;
}
/**
* Get time2
*
* @return \DateTime
*/
public function getTime2()
{
return $this->time2;
}
/**
* Set player1
*
* @param \Siriru\GSBundle\Entity\Player $player1
* @return Match
*/
public function setPlayer1(Player $player1 = null)
{
$this->player1 = $player1;
return $this;
}
/**
* Get player1
*
* @return \Siriru\GSBundle\Entity\Player
*/
public function getPlayer1()
{
return $this->player1;
}
/**
* Set player2
*
* @param \Siriru\GSBundle\Entity\Player $player2
* @return Match
*/
public function setPlayer2(Player $player2 = null)
{
$this->player2 = $player2;
return $this;
}
/**
* Get player2
*
* @return \Siriru\GSBundle\Entity\Player
*/
public function getPlayer2()
{
return $this->player2;
}
/**
* Set winner
*
* @param \Siriru\GSBundle\Entity\Player $winner
* @return Match
*/
public function setWinner(Player $winner = null)
{
$this->winner = $winner;
return $this;
}
/**
* Get winner
*
* @return \Siriru\GSBundle\Entity\Player
*/
public function getWinner()
{
return $this->winner;
}
/**
* Set type
*
* @param \Siriru\GSBundle\Entity\GoldsprintType $type
* @return Match
*/
public function setType(GoldsprintType $type)
{
$this->type = $type;
return $this;
}
/**
* Get type
*
* @return \Siriru\GSBundle\Entity\GoldsprintType
*/
public function getType()
{
return $this->type;
}
}
I generate the CRUD with php app/console doctrine:generate:crud
The localhost/app_dev/match/ give me :
An exception occurred while executing 'SELECT t0.id AS id1, t0.step AS step2, t0.time1 AS time13, t0.time2 AS time24, t0.player1_id AS player1_id5, t0.player2_id AS player2_id6, t0.winner_id AS winner_id7, t0.type_id AS type_id8 FROM match t0':
SQLSTATE[42000]: Syntax error or access violation: 1064 You have an error in your SQL syntax; check the manual that corresponds to your MariaDB server version for the right syntax to use near 'match t0' at line 1
Whyyyy ?
Thanks !
Upvotes: 0
Views: 40
Reputation: 2394
The problem is that "match" is a keyword in SQL. You should rename your table to something else.
If you don't want to change the name of the table, try to escape it with back quotes:
/**
* @ORM\Entity
* @ORM\Table(name="`match`")
*/
Upvotes: 1