无法使用查找方法或 api 平台获取我的实体?

Can't get my Entity using find method or api platform?

我遇到了一个奇怪的问题,所以问题是我在添加字段名称和类型等之后使用 symfony 命令行创建了一个名为 Option 的 Entity :

php bin/console make:migration

php bin/console doctrine:migrations:migrate

我在上面提到的广告,我使用的是 api 平台,所以为了获得所有选项,我只需输入:

localhost/api/options

但是我没有得到结果,而是在谈论 SQL 语法中的错误 t= 时遇到错误,我肯定不对此负责,因为它是它自己生成的。

所以我尝试使用传统的 symfony 方法 find 获取这些选项,但同样的错误再次出现,我尝试使用 findOneBy 和相同的方法获取一个单一的选项,所以错误是这样的:

An exception occurred while executing 'SELECT t0.id AS id_1, t0.label AS label_2 FROM option t0 WHERE t0.id = ?' with params [53]:

SQLSTATE[42000]: Syntax error or access violation: 1064 You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'option t0 WHERE t0.id = 53' at line 1

我当然不知道如何解决这个问题,但我认为该选项是一个保留字,但我不确定。

当然我不认为代码有任何问题,但有些人要求它,即使它是不必要的,但这里有一个简单的代码在我的控制器中导致了同样的问题:

$OptionManager = $this->getDoctrine()->getRepository(Option::class);
$options = $OptionManager->find(11);

如有任何帮助,我们将不胜感激

SQLSTATE[42000]:语法错误或访问冲突:1064 表示 optionreserved word in MySQL. [sic]

在 Doctrine 中,保留字必须在您的实体规范中使用反引号进行转义。

Sometimes it is necessary to quote a column or table name because of reserved word conflicts. Doctrine does not quote identifiers automatically. [sic]

/**
 * @ORM\Entity
 * @ORM\Table(name="`option`")
 */
class Option
{
    //...
}