manyToOne with nullable not working .. bug ? #4990

Open
opened 2026-01-22 14:55:50 +01:00 by admin · 3 comments
Owner

Originally created by @poolerMF on GitHub (Jan 26, 2016).

EXAMPLE 1 with JoinColumns

/**
 * @var User
 *
 * @ORM\ManyToOne(User")
 * @ORM\JoinColumns({
 *   @ORM\JoinColumn(name="created_by", referencedColumnName="id", nullable=true)
 * })
 */
private $createdBy;

-> this causes: "Integrity constraint violation: 1048 Column 'created_by' cannot be null"

EXAMPLE 2 without JoinColumns

/**
 * @var User
 *
 * @ORM\ManyToOne(User")
 * @ORM\JoinColumn(name="created_by", referencedColumnName="id", nullable=true)
 */

-> nullable works ...

I think it's bug and example 1 should works too ...

in EntityGenerator->generateAssociationMappingPropertyDocBlock() ... prefix @JoinColumns should be added only if there is more than one JoinColumn ?

Originally created by @poolerMF on GitHub (Jan 26, 2016). **EXAMPLE 1 with JoinColumns** ``` /** * @var User * * @ORM\ManyToOne(User") * @ORM\JoinColumns({ * @ORM\JoinColumn(name="created_by", referencedColumnName="id", nullable=true) * }) */ private $createdBy; ``` -> this causes: "Integrity constraint violation: 1048 Column 'created_by' cannot be null" **EXAMPLE 2 without JoinColumns** ``` /** * @var User * * @ORM\ManyToOne(User") * @ORM\JoinColumn(name="created_by", referencedColumnName="id", nullable=true) */ ``` -> nullable works ... I think it's bug and example 1 should works too ... in EntityGenerator->generateAssociationMappingPropertyDocBlock() ... prefix @JoinColumns should be added only if there is more than one JoinColumn ?
Author
Owner

@backbone87 commented on GitHub (Jan 26, 2016):

Are you sure your report is based on correct observations? Your mapping describes a join column "created_by", but your error denotes a column named "deleted_at".

@backbone87 commented on GitHub (Jan 26, 2016): Are you sure your report is based on correct observations? Your mapping describes a join column "created_by", but your error denotes a column named "deleted_at".
Author
Owner

@poolerMF commented on GitHub (Jan 26, 2016):

@backbone87 my mistake ... it's 'created_by' not 'deleted_at' in error ... I updated issue

@poolerMF commented on GitHub (Jan 26, 2016): @backbone87 my mistake ... it's 'created_by' not 'deleted_at' in error ... I updated issue
Author
Owner

@anvnguyen commented on GitHub (Jul 29, 2020):

is there any update on this issue? I encounter similar one.

@anvnguyen commented on GitHub (Jul 29, 2020): is there any update on this issue? I encounter similar one.
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: doctrine/archived-orm#4990