Mapping discrepancy for ManyToOne with new inference #6774

Closed
opened 2026-01-22 15:38:23 +01:00 by admin · 4 comments
Owner

Originally created by @TristanPouliquen on GitHub (Jun 30, 2021).

Hello,

I've come across a discrepancy in the SQL produced by Doctrine for ManyToOne annotations. As stated in the official documentation, the JoinColumn should infer the nullable from the attribute type definition.

However, this is actually not the case.

I've created a minimal reproduction case in this repository.

As you can see in EntityC, I've defined one ManyToOne with PHP7.4 typed attributes and the other without it.

In the dump of my SQL schema, you can see that the SQL statements for both fields are not the same, when they should normally be.

The statement for the relationship with EntityA, defined with a typed attribute, has a DEFAULT NULL clause that should not happen.

How can I help going ahead in fixing this?

Originally created by @TristanPouliquen on GitHub (Jun 30, 2021). Hello, I've come across a discrepancy in the SQL produced by Doctrine for ManyToOne annotations. As stated in [the official documentation](https://www.doctrine-project.org/projects/doctrine-orm/en/2.9/reference/association-mapping.html#mapping-defaults), the `JoinColumn` should infer the `nullable` from the attribute type definition. However, this is actually not the case. I've created a minimal reproduction case in [this repository](https://github.com/TristanPouliquen/orm_mapping_reproduction). As you can see in [EntityC](https://github.com/TristanPouliquen/orm_mapping_reproduction/src/Entity/EntityC.php), I've defined one `ManyToOne` with PHP7.4 typed attributes and the other without it. In the [dump of my SQL schema](https://github.com/TristanPouliquen/orm_mapping_reproduction/schema_dump.sql), you can see that the SQL statements for both fields are not the same, when they should normally be. The statement for the relationship with EntityA, defined with a typed attribute, has a `DEFAULT NULL` clause that should not happen. How can I help going ahead in fixing this?
admin closed this issue 2026-01-22 15:38:23 +01:00
Author
Owner

@TristanPouliquen commented on GitHub (Jul 1, 2021):

There also seems to have an error in the inference of the nullable attribute for simple types. I have updated my reproduction to insert a typed nullable string attribute, that generates a VARCHAR NOT NULL in my Doctrine schema.

@TristanPouliquen commented on GitHub (Jul 1, 2021): There also seems to have an error in the inference of the nullable attribute for simple types. I have updated my reproduction to insert a typed nullable string attribute, that generates a VARCHAR NOT NULL in my Doctrine schema.
Author
Owner

@greg0ire commented on GitHub (Jul 1, 2021):

How can I help going ahead in fixing this?

Finding who introduced the new inference and it which PR would help finding the best people to help with this `git log -S 'some string' should help with this.

@greg0ire commented on GitHub (Jul 1, 2021): > How can I help going ahead in fixing this? Finding who introduced the new inference and it which PR would help finding the best people to help with this `git log -S 'some string' should help with this.
Author
Owner

@mbabker commented on GitHub (Jul 1, 2021):

Nullable inference was backed out in https://github.com/doctrine/orm/pull/8732 due to B/C issues.

@mbabker commented on GitHub (Jul 1, 2021): Nullable inference was backed out in https://github.com/doctrine/orm/pull/8732 due to B/C issues.
Author
Owner

@TristanPouliquen commented on GitHub (Jul 1, 2021):

Ah, thanks to both of you. I had tried to look for similar issues but did not come across these ones.

Too bad it has been reversed, but I understand the BC point of view. I'll wait for the 3.x to remove these last bits of redundant annotations!

Cheers!

@TristanPouliquen commented on GitHub (Jul 1, 2021): Ah, thanks to both of you. I had tried to look for similar issues but did not come across these ones. Too bad it has been reversed, but I understand the BC point of view. I'll wait for the 3.x to remove these last bits of redundant annotations! Cheers!
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: doctrine/archived-orm#6774