Get the column type of the ID field, if the entity is identified by a related entity #10717
Unanswered
floriandammeyer
asked this question in
Support Questions
Replies: 0 comments
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
-
I have the following situation: one 'parent' entity has a related 'child' entity with a OneToOne relation. The child entity cannot exist without the parent entity, so the child entity derives its own identity from the parent entity. The catch: I am not using plain old integer identities, but ULIDs instead (using the according Symfony package):
This seems to work fine for the most part, at least generating the migrations works fine (it creates the correct ULID database columns, especially "child.parent_id" is being created correctly as a ULID column) and also fetching a parent entity and joining the child entity into the result seems to work. So in general, Doctrine seems to be able to handle the column type of the
Child
entity's ID column correctly.However, when other libraries (in this case ApiPlatform) try to automatically generate queries for the
Child
entity using the QueryBuilder and the ClassMetadata, the parameter type for the ID field is not being set correctly, so no result is being returned.For example, ApiPlatform wants to create a query to fetch a single
Child
entity. It correctly adds a where clause for "parent" to the QueryBuilder, because this is the identifier of aChild
entity. But later on, the type of that "parent" parameter is being set to the wrong value, because ApiPlatform uses$doctrineClassMetadata->getTypeOfField("parent")
to get the column type, where$doctrineClassMetadata
is the ClassMetadata ofChild
. Because there is no actual field definition for the identifier property, that method call returnsnull
and therefore the parameter type is not being set and instead it is assumed to be the default type of integer.I looked at the ClassMetadata class to see if this is a bug in ApiPlatform and there is another way to get the column type of the ID column in this case, but there does not seem to be one.
How do I get the column type for the ID column of
Child
, which should be ULID, in this case? Do I have to add some sort of column definition annotation to the ID property of myChild
entity or do you have to use some other method ofClassMetadata
to get the correct column type?Beta Was this translation helpful? Give feedback.
All reactions