Skip to content
This repository has been archived by the owner on Feb 19, 2025. It is now read-only.

Double hydration problem #151

Open
MuntzMathias opened this issue Sep 12, 2020 · 0 comments
Open

Double hydration problem #151

MuntzMathias opened this issue Sep 12, 2020 · 0 comments

Comments

@MuntzMathias
Copy link

Hello,

Here is how I use this hydrator

  • I do an SQL query
  • I get the result in the form of an array
  • I hydrate the data in a DTO
  • I send this DTO to another service
  • This service also executes an SQL query and hydrates the data once in the DTO

But I have a problem with nullable properties, indeed the hydrator will hydrate the null value for these properties, if they are not present in the data array.

I am able to correct the problem by modifying the HydratorMethodsVisitor class at line 110 by replacing
return ['$ object->'. $ propertyName. '='. $ inputArrayName. '['. $ escapedName. '] ?? null; '];
by
return ['$ object->'. $ propertyName. '='. $ inputArrayName. '['. $ escapedName. '] ?? '. '$ object->'. $ propertyName. ' ?? null; '];

So my question is, shouldn't the hydrator only hydrate properties if it exists in the array, like Laminas Hydrator ?

Should I use my own FileWriterGeneratorStrategy to overcome this problem ?

Thanks

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant