1

lets say I have a single table inheritance classes like in the doctrine documentation example. The Employee entity has a new property $account:

<?php
namespace MyProject\Model;

/**
 * @Entity
 * @InheritanceType("SINGLE_TABLE")
 * @DiscriminatorColumn(name="discr", type="string")
 * @DiscriminatorMap({"person" = "Person", "employee" = "Employee"})
 */
class Person
{
    // ...
}

/**
 * @Entity
 */
class Employee extends Person
{

    /**
    * @ORM\ManyToOne(targetEntity="Account")
    * @ORM\JoinColumn(nullable=true)
    *
    * @var Account
    */
    protected $account;

}

How can I get all the Person entities using DQL with a (eager) joined Account entities in case the Person is an instance of Employee as i cannot write a standard leftJoin because the Person enity has no property Account?

Thanks

Lunack
  • 343
  • 1
  • 5
  • 14
  • You could have a look at [filtering Collections](http://docs.doctrine-project.org/projects/doctrine-orm/en/latest/reference/working-with-associations.html#filtering-collections). However, I think you might be doing this the wrong way around, as indeed: a Person does not have an Account. Why don't you do something like `$account->getEmployees()` (so inverse the direction)? – rkeet Mar 20 '18 at 11:59
  • (As a side note: you need **not** declare a `DiscriminatorMap`, see [this answer](https://stackoverflow.com/a/45015357/1155833) by myself) – rkeet Mar 20 '18 at 12:01
  • I find the answer here https://stackoverflow.com/questions/18605782/doctrine2-self-join-how-to-join-on-self-without-relationship-column – tarasikarius Nov 30 '18 at 12:11

0 Answers0