I'm trying to filter out the children where the parent consists of a composite primary key, the parent is called subject and the children is courses:
Subject:
class Subject
{
/**
* @var integer
*
* @Column(type="integer")
* @Id
* @GeneratedValue(strategy="NONE")
*/
protected $id;
/**
* @var integer
*
* @Column(type="integer")
* @Id
*/
protected $customer_id;
/**
* @var ArrayCollection
*
* @OneToMany(targetEntity="Course", mappedBy="subject")
*/
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 the "subject_id" and "subject_customer_id", my problem is that I can't filter out courses without joining subject, 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 ]: A single-valued association path expression to an entity with a composite primary key is not supported. Explicitly name the components of the composite primary key in the query.
The only why I can get this working is by inner joining subject, 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();
Is there any way to retrieve the courses based on the subject primary keys without joining subject?