Entity as a parameter in a Query is not correctly processed to its identifier value #5284

Open
opened 2026-01-22 15:03:25 +01:00 by admin · 3 comments
Owner

Originally created by @fancyweb on GitHub (Oct 6, 2016).

Hello,
I've just found a problem in the processParameterValue method of the AbstractQuery class (https://github.com/doctrine/doctrine2/blob/master/lib/Doctrine/ORM/AbstractQuery.php#L423).

If you have an entity as a parameter in a Query, if the ClassMetadata of this entity has not been fetched yet, the entity won't be transformed to its identifier to be used as the parameter in the final generated sql query. This is because the hasMetadataFor method is used, and this method only check in the already fetched ClassMetadata array.

Originally created by @fancyweb on GitHub (Oct 6, 2016). Hello, I've just found a problem in the `processParameterValue` method of the `AbstractQuery` class (https://github.com/doctrine/doctrine2/blob/master/lib/Doctrine/ORM/AbstractQuery.php#L423). If you have an entity as a parameter in a `Query`, if the `ClassMetadata` of this entity has not been fetched yet, the entity won't be transformed to its identifier to be used as the parameter in the final generated sql query. This is because the `hasMetadataFor` method is used, and this method only check in the already fetched `ClassMetadata` array.
admin added the Bug label 2026-01-22 15:03:25 +01:00
Author
Owner

@Ocramius commented on GitHub (Oct 6, 2016):

@fancyweb ugly, but indeed true. Possibly to be solved in 3.x, when we change the metadata approach completely.

@Ocramius commented on GitHub (Oct 6, 2016): @fancyweb ugly, but indeed true. Possibly to be solved in 3.x, when we change the metadata approach completely.
Author
Owner

@fancyweb commented on GitHub (Oct 6, 2016):

@Ocramius Couldn't we use the method getMetadataFor method in a try catch block instead ?

@fancyweb commented on GitHub (Oct 6, 2016): @Ocramius Couldn't we use the method `getMetadataFor` method in a try catch block instead ?
Author
Owner

@Ocramius commented on GitHub (Oct 6, 2016):

in a try catch block instead ?

Yes, that can also be done, and should be simple too, for now. Needs some test case scenarios though:

  • non-mapped class
  • non-loaded metadata
  • loaded metadata
@Ocramius commented on GitHub (Oct 6, 2016): > in a try catch block instead ? Yes, that can also be done, and should be simple too, for now. Needs some test case scenarios though: - non-mapped class - non-loaded metadata - loaded metadata
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: doctrine/archived-orm#5284