doctrine/orm

Make IDENTITY function work with joined columns

Open

#8,043 opened on Feb 27, 2020

View on GitHub
 (4 comments) (0 reactions) (0 assignees)PHP (2,539 forks)batch import
BugHacktoberfest

Repository metrics

Stars
 (10,176 stars)
PR merge metrics
 (Avg merge 29d 6h) (13 merged PRs in 30d)

Description

Feature Request

Q A
New Feature yes
RFC no
BC Break no

Summary

On https://www.doctrine-project.org/projects/doctrine-orm/en/2.7/reference/dql-doctrine-query-language.html#dql-select-examples it is said

the IDENTITY() DQL function also works for composite primary keys

But if these keys are part of another association they won’t be found in fields but in associations mapping, hence throwing.

Example

Given the following entities

class Contract
{
    /**
     * @ORM\ManyToOne(targetEntity="Agent")
     * @ORM\Id
     */
    private $agent;

    /**
     * @ORM\ManyToOne(targetEntity="Agency")
     * @ORM\Id
     */
    private $agency;
}

class Estate
{
    /**
     * @ORM\ManyToOne(targetEntity="Contract")
     * @ORM\JoinColumns({
     *  @ORM\JoinColumn(name="contract_agent_id", referencedColumnName="agent_id"),
     *  @ORM\JoinColumn(name="contract_agency_id", referencedColumnName="agency_id"),
     * })
     */
    protected $contract;
}

I expected to be able to write IDENTITY(estate.contract, 'agent_id').

Is this something that could be implemented?

Contributor guide