执行'SELECT count(DISTINCT o0_.id) AS sclr_0 FROM Order o0_'时发生异常



在Symfony 3.4.8上使用SonataAdminBundle时,我遇到了以下问题:

当我去查看我的表列表时,我收到以下错误。

执行"选择计数(不同o0_.id("时发生异常 正如第 o0_ 号订单中的sclr_0:

SQLSTATE[42000]:语法错误或访问冲突:1064 您有一个 您的 SQL 语法错误;检查与您的手册相对应的手册 MySQL 服务器版本,用于在"订单o0_"附近使用的正确语法 第 1 行

我的实体\订单.php

<?php
namespace GobusgoGobusgoBundleEntity;
use DoctrineORMMapping as ORM;
/**
 * Order
 *
 * @ORMTable(name="Order")
 *  @ORMEntity(repositoryClass="GobusgoGobusgoBundleRepositoryOrderRepository")
 */
class Order
{
    /**
     * @var int
     *
     * @ORMColumn(name="id", type="integer")
     * @ORMId
     * @ORMGeneratedValue(strategy="AUTO")
     */
    protected $id;
    /**
     * @ORMManyToOne(targetEntity="GobusgoGobusgoBundleEntityUser")
     */
    protected $userId;
    /**
     * @ORMManyToOne(targetEntity="GobusgoGobusgoBundleEntityCargo")
     */
    protected $cargoId;
    /**
     * @var float
     *
     * @ORMColumn(type="float")
     */
    protected $price;
    /**
     * @var float
     *
     * @ORMColumn(name="quantity_of_cargo", type="float")
     */
    protected $quantityOfCargo;
    /**
     * @ORMManyToOne(targetEntity="GobusgoGobusgoBundleEntityAddress")
     *
     */
    protected $shippingAddress;
    /**
     * @ORMManyToOne(targetEntity="GobusgoGobusgoBundleEntityAddress")
     *
     */
    protected $deliveryAddress;
    /**
     * @ORMManyToOne(targetEntity="GobusgoGobusgoBundleEntityAddress")
     *
     */
    protected $additionalAddress1;
    /**
     * @ORMManyToOne(targetEntity="GobusgoGobusgoBundleEntityAddress")
     *
     */
    protected $additionalAddress2;
    /**
     * @ORMManyToOne(targetEntity="GobusgoGobusgoBundleEntityAddress")
     *
     */
    protected $additionalAddress3;
    /**
     * @ORMManyToOne(targetEntity="GobusgoGobusgoBundleEntityAddress")
     *
     */
    protected $additionalAddress4;
    /**
     * @ORMManyToOne(targetEntity="GobusgoGobusgoBundleEntityAddress")
     *
     */
    protected $additionalAddress5;
    /**
     *
     *
     * @ORMColumn(type="datetime")
     */
    protected $dateOfOrder;
    /**
     * @var float
     *
     * @ORMColumn(type="float")
     */
    protected $status;
    /**
     * @return int
     */
    public function getId()
    {
        return $this->id;
    }
    /**
     * @param int $id
     */
    public function setId($id)
    {
        $this->id = $id;
    }
    /**
     * @return mixed
     */
    public function getUserId()
    {
        return $this->userId;
    }
    /**
     * @param mixed $userId
     */
    public function setUserId($userId)
    {
        $this->userId = $userId;
    }
    /**
     * @return mixed
     */
    public function getCargoId()
    {
        return $this->cargoId;
    }
    /**
     * @param mixed $cargoId
     */
    public function setCargoId($cargoId)
    {
        $this->cargoId = $cargoId;
    }
    /**
     * @return float
     */
    public function getPrice()
    {
        return $this->price;
    }
    /**
     * @param float $price
     */
    public function setPrice($price)
    {
        $this->price = $price;
    }
    /**
     * @return float
     */
    public function getQuantityOfCargo()
    {
        return $this->quantityOfCargo;
    }
    /**
     * @param float $quantityOfCargo
     */
    public function setQuantityOfCargo($quantityOfCargo)
    {
        $this->quantityOfCargo = $quantityOfCargo;
    }
    /**
     * @return mixed
     */
    public function getShippingAddress()
    {
        return $this->shippingAddress;
    }
    /**
     * @param mixed $shippingAddress
     */
    public function setShippingAddress($shippingAddress)
    {
        $this->shippingAddress = $shippingAddress;
    }
    /**
     * @return mixed
     */
    public function getDeliveryAddress()
    {
        return $this->deliveryAddress;
    }
    /**
     * @param mixed $deliveryAddress
     */
    public function setDeliveryAddress($deliveryAddress)
    {
        $this->deliveryAddress = $deliveryAddress;
    }
    /**
     * @return mixed
     */
    public function getAdditionalAddress1()
    {
        return $this->additionalAddress1;
    }
    /**
     * @param mixed $additionalAddress1
     */
    public function setAdditionalAddress1($additionalAddress1)
    {
        $this->additionalAddress1 = $additionalAddress1;
    }
    /**
     * @return mixed
     */
    public function getAdditionalAddress2()
    {
        return $this->additionalAddress2;
    }
    /**
     * @param mixed $additionalAddress2
     */
    public function setAdditionalAddress2($additionalAddress2)
    {
        $this->additionalAddress2 = $additionalAddress2;
    }
    /**
     * @return mixed
     */
    public function getAdditionalAddress3()
    {
        return $this->additionalAddress3;
    }
    /**
     * @param mixed $additionalAddress3
     */
    public function setAdditionalAddress3($additionalAddress3)
    {
        $this->additionalAddress3 = $additionalAddress3;
    }
    /**
     * @return mixed
     */
    public function getAdditionalAddress4()
    {
        return $this->additionalAddress4;
    }
    /**
     * @param mixed $additionalAddress4
     */
    public function setAdditionalAddress4($additionalAddress4)
    {
        $this->additionalAddress4 = $additionalAddress4;
    }
    /**
     * @return mixed
     */
    public function getAdditionalAddress5()
    {
        return $this->additionalAddress5;
    }
    /**
     * @param mixed $additionalAddress5
     */
    public function setAdditionalAddress5($additionalAddress5)
    {
        $this->additionalAddress5 = $additionalAddress5;
    }
    /**
     * @return mixed
     */
    public function getDateOfOrder()
    {
        return $this->dateOfOrder;
    }
    /**
     * @param mixed $dateOfOrder
     */
    public function setDateOfOrder($dateOfOrder)
    {
        $this->dateOfOrder = $dateOfOrder;
    }
    /**
     * @return float
     */
    public function getStatus()
    {
        return $this->status;
    }
    /**
     * @param float $status
     */
    public function setStatus($status)
    {
        $this->status = $status;
    }

}

我的管理员\订单管理员.php

<?php
namespace GobusgoGobusgoBundleAdmin;
use GobusgoGobusgoBundleEntityCargo;
use GobusgoGobusgoBundleEntityUser;
use SonataAdminBundleAdminAbstractAdmin;
use SonataAdminBundleDatagridListMapper;
use SonataAdminBundleDatagridDatagridMapper;
use SonataAdminBundleFormFormMapper;
use SonataAdminBundleFormTypeModelType;
class OrderAdmin extends AbstractAdmin
{
    protected $baseRouteName = 'order_admin';
    protected $baseRoutePattern = 'order_admin';
    protected function configureFormFields(FormMapper $formMapper)
    {
        $formMapper
            ->add('userId', ModelType::class,[
                'class'=>User::class,
                'property'=>'fullName',
            ])
            ->add('cargoId', ModelType::class, [
                'class'=>Cargo::class,
                'property'=>'name'
            ])
        ;
    }
    protected function configureDatagridFilters(DatagridMapper $datagridMapper)
    {
        $datagridMapper->add('id');
    }
    protected function configureListFields(ListMapper $listMapper)
    {
        $listMapper->addIdentifier('id');
    }
}

My services.yml 包含以下代码

admin.order:
    class: GobusgoGobusgoBundleAdminOrderAdmin
    arguments: [~, GobusgoGobusgoBundleEntityOrder, ~]
    tags:
        - { name: sonata.admin, manager_type: orm, label: Заказ , group: "app.admin.group.admin" }
    public: true

请帮帮我...

原则按

原样将表名添加到查询中,不带反引号。因此,mysql 认为这是一个语法错误ORDER BY因为这是不区分大小写的保留 sql 关键字。

要解决此问题,您可以在映射中重命名表,例如

@ORMTable(name="Order_postfix")

他们说,您还可以通过在映射中使用反引号来手动转义表名。喜欢这个:

@ORMTable(name="`Order`")

相关内容

  • 没有找到相关文章

最新更新