主义查询崩溃 [英] Doctrine query crashing

查看:78
本文介绍了主义查询崩溃的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

非常奇怪。我已经从教义中使用了这种方法数百次。我有一个简单的控制器,将id作为参数。 Doctrine生成的查询是错误的,并且崩溃。

Very very weird. I have used this method from doctrine hundreds of times. I have a simple controller that takes an id as parameter. The query that Doctrine generates is wrong and crash.

/**
 * @Security("has_role('ROLE_ADMIN')")
 * @return Response
 */
public function editSellerAction($id)
{
    $em  = $this->getDoctrine()->getManager();
    $seller = $em->getRepository('SiteUserBundle:Seller')->find($id);

    // ...
    $form = $this->createForm(new SellerType(), $seller, array(
        'method' => 'POST'
    ));
    // ...
}

生成的查询如下


[2/2] DBALException:执行'SELECT t1.id AS id2,t1.username AS username3,t1.password时发生异常AS密码4,t1.firstname AS姓氏5,t1.lastname AS姓氏6来自卖方t1哪里 t0 .id =?带有参数[[2]]的LIMIT 1':

[2/2] DBALException: An exception occurred while executing 'SELECT t1.id AS id2, t1.username AS username3, t1.password AS password4, t1.firstname AS firstname5, t1.lastname AS lastname6 FROM seller t1 WHERE t0.id = ? LIMIT 1' with params ["2"]:

SQLSTATE [42S22]:找不到列:1054未知列't0.id '在'where子句'+

SQLSTATE[42S22]: Column not found: 1054 Unknown column 't0.id' in 'where clause' +

抛出错误是有道理的,因为它在查看 WHERE t1.id时正在查看 WHERE t0.id。我尝试使用phpmyadmin与t1进行查询,并且可以使用。

The error thrown makes sense because it's looking at "WHERE t0.id" when it should be looking at "WHERE t1.id". I tried the query with t1 using phpmyadmin and it works.

知道什么可能导致此问题吗?

Any idea what might cause this issue?

/**
 * Seller have access to their customer and are able to RW access to the customers
 *
 * @ORM\Table("seller")
 * @ORM\Entity
 * @author Michael Villeneuve
 */
class Seller extends User
{

    /**
     * @var array
     * 
     * @ORM\OneToMany(targetEntity="Customer", mappedBy="seller", cascade={"persist", "remove"})
     * @ORM\JoinColumn(name="seller_id", referencedColumnName="id")
     **/
    protected $customers; 

    /**
     * @var string
     *
     * @ORM\Column(name="firstname", type="string", length=255, nullable=false)
     */
    protected $firstname;

    /**
     * @var string
     *
     * @ORM\Column(name="lastname", type="string", length=255, nullable=false)
     */
    protected $lastname;

    // Other attributes and only getters/setter


/**
 *
 * @ORM\Entity
 */
class User implements UserInterface
{
    /**
     * @var integer
     *
     * @ORM\Column(name="id", type="integer")
     * @ORM\Id
     * @ORM\GeneratedValue(strategy="AUTO")
     */
    private $id;

    /**
     * @ORM\Column(type="string", length=255, unique=true)
     */
    private $username;

    /**
     * @ORM\Column(type="string", length=64)
     */
    private $password;

我有3个扩展用户的实体(客户,管理员和卖家)。

I have 3 entities that extends the User (customer, admin and seller).

推荐答案

更新的链接:> https://www.doctrine-project.org/projects/doctrine-orm/zh/2.7/reference/inheritance-mapping.html

在映射的超类上阅读一些内容: http://docs.doctrine-project.org/en/latest/reference/inheritance-mapping.html 。基本上,您的抽象基本用户类本身不能是实体。

Read up a bit on mapped super classes: http://docs.doctrine-project.org/en/latest/reference/inheritance-mapping.html. Basically, your abstract base user class cannot itself be an entity.

因此,将@ ORM\Entity行从User类中删除。这就是表0(t0)的来源。

So take the @ORM\Entity line out of your User class. That is where the table 0 (t0) is coming from.

这篇关于主义查询崩溃的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆