I'm trying to filter a list of "Client" entities based on properties of an associated entity called Account. The problem is that the Account entity it's just a base class and the actual properties for filtering lives in their child entities (PersonalAccount and EnterpriseAccount) but doctrine only let my access properties of the Account base class.
To summarize, here's my situation:
The Client entity:
class Client
{
/** @ORM\OneToMany(targetEntity="Account", mappedBy="client") */
protected $accounts;
}
The base Account entity:
class Account
{
/** @ORM\ManyToOne(targetEntity="Client", inversedBy="accounts") */
protected $client;
}
PersonalAccount entity (child of Account)
class PersonalAccount extends Account
{
/** @ORM\Column() */
protected $name;
}
In my controller I tried:
$qb = $em->getRepository('MyBundle:Client')->createQueryBuilder('cl');
$query = $qb->select('cl')
->innerJoin('cl.accounts', 'acc')
->where('acc.name = :name')
->setParameter('name', 'Jhon')
->getQuery();
But it throws an exception because the base class Account doesn't have a property called "name".
How can I filter the Client entity using properties of the inherited PersonalAccount class?