非常非常奇怪.我已经从教义中使用了这种方法数百次.我有一个简单的控制器,它将id作为参数.Doctrine生成的查询是错误的并且崩溃.
/** * @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 password4,t1.firstname AS firstname5,t1.lastname AS lastname6 FROM seller t1 WHERE t0 .id时发生异常=?使用params ["2"]限制1':
SQLSTATE [42S22]:未找到列:1054'where子句'中的未知列't0.id'+
抛出的错误是有道理的,因为当它应该查看"WHERE t1.id"时它正在查看"WHERE t0.id".我使用phpmyadmin尝试了t1的查询,它的工作原理.
知道什么可能导致这个问题吗?
/** * 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个实体扩展了用户(客户,管理员和卖家).
更新链接:https://www.doctrine-project.org/projects/doctrine-orm/en/2.7/reference/inheritance-mapping.html
阅读一下映射的超类:http://docs.doctrine-project.org/en/latest/reference/inheritance-mapping.html.基本上,您的抽象基本用户类本身不能是实体.
所以从你的User类中取出@ORM\Entity行.这就是表0(t0)的来源.