Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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 join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant