mirror of
https://github.com/doctrine/orm.git
synced 2026-03-24 06:52:09 +01:00
Impossible to have part of a composite key to be null in a ternary relationship ? #5659
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 @CPASimUSante on GitHub (Aug 24, 2017).
Originally assigned to: @Ocramius on GitHub.
I have an entity that holds relation with 3 entities Session, User and Institution.
but when i try to generate the schema, i have :
the three part of the key have NOT NULL even if i add explicitly nullable=true...
i've validated the schema with a app/console doctrine:schema:validate and it's OK
I've read the doc for ID annotation
and
those for join column with nullable
Finally , I'm not sure to understand the implication of "General Considerations" part for the composite keys in the doc
It seems wrong to have to change a "regular" ternary relationship for a classical Entity with onr Primary key and userId, sessionId, institutionId as foreign keys, which can be null.
Why can't a keys like (userIdValue, null, institutionIdValue), (userIdValue, sessionId, institutionIdValue), (null, null, institutionIdValue)... as long as the composite key stay unique
Did i miss something in the doc, is it a limitation or is is a real bug ?
Thank you
@Ocramius commented on GitHub (Aug 25, 2017):
@CPASimUSante Doctrine ORM does not allow nor support
NULLfor primary key fields. If a field is an identifier, then it should be forced to beNOT NULLby the ORM.From the MySQL docs, for example:
In other engines, a primary key with nullable fields would also make no sense, because
NULLis not used for uniqueness comparison (as it cannot be compared to other values), so you may end up having two records with a PK(1, 2, NULL), even though you have a primary key set on these 3 columns.Closing as
invalid.@CPASimUSante commented on GitHub (Aug 25, 2017):
Thank you for your confirmation/explanation. I'll use the "regular" entity system with primary key then.
@CPASimUSante commented on GitHub (Aug 25, 2017):
Not to reopen, but as a side note, NULL can not indeed be compared to a value, but it can be checked : null or not null, which does 2 states => values possible. But i understand it would be a different kind of check...
@Ocramius commented on GitHub (Aug 25, 2017):
The DB doesn't check it with the uniqueness of a
PRIMARY KEYconstraint, which is the first problem.