I am trying to filter out child elements in which the parent element consists of a composite primary key, the parent object is called the subject, and the children are courses:
Subject:
class Subject
{
protected $id;
protected $customer_id;
private $courses;
...
}
Course:
class Course
{
...
/**
* @var Subject
*
* @ManyToOne(targetEntity="Subject", inversedBy="courses")
* @JoinColumns({
* @JoinColumn(name="subject_id", referencedColumnName="id"),
* @JoinColumn(name="subject_customer_id", referencedColumnName="customer_id")
* })
*/
private $subject;
}
I have "subject_id" and "subject_customer_id", my problem is that I cannot filter out courses without joining the topic when I write this:
$this->em->createQuery("SELECT c FROM Course c WHERE c.subject = :subject")
->setParameters( array('subject' => array( 'subject_id' => $subject_id, 'subject_customer_id' => $subject_customer_id ) ) )
->getResult();
I get the following error:
Doctrine \ ORM \ Query \ QueryException [0]: The unambiguous association of path for an object with a composite primary key is not supported. Explicitly name the composite primary key components in the query.
The only thing I can get this work for is the internal connection of the object, for example:
$this->em->createQuery("SELECT c FROM Course c INNER JOIN c.subject s WITH s.id = :subject AND s.customer_id = :customer")
->setParameters( array( 'subject' => $subject_id, 'customer' => $customer_id ) )
->getResult();
?