Doctrine 2 and DQL Interactive Keys Combine

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
{
   /**
     * @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 "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();

?

+5
1

DQL (. https://github.com/doctrine/doctrine2/blob/2.3.2/lib/Doctrine/ORM/Persisters/BasicEntityPersister.php#L1641-L1643).

- :

SELECT
    c
FROM
    Course c
INNER JOIN 
    c.subject s 
WHERE 
    s.id = :subject 
    AND 
    s.customer_id = :customer

: 2.4.

+2

All Articles