实体错误SQL语法

时间:2014-03-20 11:38:48

标签: symfony doctrine-orm

这里是一个实体:

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;
    }
}

我使用php app/console doctrine:generate:crud

生成CRUD

localhost / app_dev / match /给我:

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

为什么?

谢谢!

1 个答案:

答案 0 :(得分:1)

问题是“匹配”是SQL中的关键字。您应该将表重命名为其他内容。

如果您不想更改表的名称,请尝试使用后引号将其转义:

/**
 * @ORM\Entity
 * @ORM\Table(name="`match`")
 */