Doctrine query crashing

doctrine-orm, symfony

Solution

Updated link: https://www.doctrine-project.org/projects/doctrine-orm/en/2.7/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.

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

Problem

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' )); // ... } ``` The query generated is the following [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]: Column not found: 1054 Unknown column 't0.id' in 'where clause' + 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; ``` I have 3 entities that extends the User (customer, admin and seller).

Original source