mirror of
https://github.com/doctrine/orm.git
synced 2026-03-23 22:42:18 +01:00
ManyToOne for composite foreign key with null values #6957
Reference in New Issue
Block a user
Delete Branch "%!s()"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
Originally created by @danijelvenus on GitHub (Apr 7, 2022).
Bug Report
Summary
We need to defined orm mapping for tables with composite keys
Table A
Column A1 not null
Column A2 not null
Column A3 not null
PK for table A is composite and consists of A1 and A2 columns
Table B
Column B1 not null
Column B2 not null
Column B3 null
PK for table B is B1 and B2.
Table B has foreign key to table A (B1 -> A1, B3 -> A2)
We need ManyToOne mapping in entity A
Current behavior
In case when there are null values in fk column B3, but B1 is not null
Exception is thrown when try to read data using Paginator and QueryBuilder
Doctrine\ORM\Exception\MissingIdentifierField::fromFieldAndClass
with message
The identifier 'colum_name' is missing for a query of 'entity_name'
How to reproduce
The exception is thrown in case when there is unitId with null, but orgId is not null in WebNews in DB
with the message
The identifier unitId is missing for a query of '...\OrganizationalUnits'
Expected behavior
Result of paginator and query builder should be a list of rows from database
Is seems to work if we remove marked code below from elseif condition
Doctrine\ORM\UnitOfWork createEntity method
$targetClass->containsForeignIdentifier
@Basch commented on GitHub (Mar 21, 2024):
A possible solution is to change the testing condition in UnitOfWork.php line 2470:
This way doctrine still try to find relation entity when value is set to null but only if the target entity column is nullable.
@Justinas-Jurciukonis commented on GitHub (Mar 29, 2024):
This change actually helps with partial foreign keys (when not all fields are set)