DDC-1614: On OneToOne mappings with Primary Key same as Foreign Key, using @Id in the foreign association does not carry over when running "generate-entities" with --generate-annotations=1 #2030

Open
opened 2026-01-22 13:37:56 +01:00 by admin · 0 comments
Owner

Originally created by @doctrinebot on GitHub (Jan 22, 2012).

Originally assigned to: @Ocramius on GitHub.

Jira issue originally created by user rfink:

When having a OneToOne mapping that has a primary key that is the same as the foreign key, using the @Id attribute does not carry over when generating entities.

Example code:

class User
{
    /**
     * @Id @Column(type="integer", nullable=false, columnDefinition="INT UNSIGNED NOT NULL AUTO_INCREMENT")
     * @GeneratedValue(strategy="AUTO")
     */
    private $id;

    /**
     * @OneToOne(targetEntity="User_ExtraAttrs", cascade={"persist","remove","detach","merge","refresh"}, mappedBy="User")
     * @JoinColumn(name="id", referencedColumnName="id")
     */
    private $UserAttrs;
}

class User_ExtraAttrs
{
    /**
     * @OneToOne(targetEntity="User", cascade={"all"}, inversedBy="UserAttrs")
     * @Id
     * @JoinColumn(name="VehicleID", referencedColumnName="VehicleID")
     */
    private $User;
}

When running "doctrine orm:generate-entities --regenerate-entities=1 --generate-annotations=1", the @Id in User_ExtraAttrs does not carry over. It must be manually inserted.

Originally created by @doctrinebot on GitHub (Jan 22, 2012). Originally assigned to: @Ocramius on GitHub. Jira issue originally created by user rfink: When having a OneToOne mapping that has a primary key that is the same as the foreign key, using the @Id attribute does not carry over when generating entities. Example code: ```php class User { /** * @Id @Column(type="integer", nullable=false, columnDefinition="INT UNSIGNED NOT NULL AUTO_INCREMENT") * @GeneratedValue(strategy="AUTO") */ private $id; /** * @OneToOne(targetEntity="User_ExtraAttrs", cascade={"persist","remove","detach","merge","refresh"}, mappedBy="User") * @JoinColumn(name="id", referencedColumnName="id") */ private $UserAttrs; } class User_ExtraAttrs { /** * @OneToOne(targetEntity="User", cascade={"all"}, inversedBy="UserAttrs") * @Id * @JoinColumn(name="VehicleID", referencedColumnName="VehicleID") */ private $User; } ``` When running "doctrine orm:generate-entities --regenerate-entities=1 --generate-annotations=1", the @Id in User_ExtraAttrs does not carry over. It must be manually inserted.
admin added the ImprovementInvalid labels 2026-01-22 13:37:56 +01:00
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: doctrine/archived-orm#2030