DDC-1289: orm:generate-entities create incorrect setters for ManyToOne and OneToOne #1619

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

Originally created by @doctrinebot on GitHub (Jul 23, 2011).

Originally assigned to: @beberlei on GitHub.

Jira issue originally created by user matthewmatician:

When using the CLI tool to generate entities, ManyToOne setters are not being written correctly when the key-field is allowed to be null.

For example, on this annotation:

/**** 
 *@OneToOne(targetEntity="AdminRole")
 */
protected $adminRole;

the following method is created:

public function setAdminRole(\path\to\namespace\AdminRole $adminRole)
{...}

HOWEVER: the method declaration should be like this:

public function setAdminRole(\path\to\namespace\AdminRole $adminRole = null)
{...}

This allows for setting null values without throwing an error. As it is currently, this is only correct when the annotation includes @joinColumn(... nullable=false)

Originally created by @doctrinebot on GitHub (Jul 23, 2011). Originally assigned to: @beberlei on GitHub. Jira issue originally created by user matthewmatician: When using the CLI tool to generate entities, ManyToOne setters are not being written correctly when the key-field is allowed to be null. For example, on this annotation: ``` /**** *@OneToOne(targetEntity="AdminRole") */ protected $adminRole; ``` the following method is created: ``` public function setAdminRole(\path\to\namespace\AdminRole $adminRole) {...} ``` HOWEVER: the method declaration should be like this: ``` public function setAdminRole(\path\to\namespace\AdminRole $adminRole = null) {...} ``` This allows for setting null values without throwing an error. As it is currently, this is only correct when the annotation includes @joinColumn(... nullable=false)
admin added the Bug label 2026-01-22 13:20:09 +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#1619