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

Double hydration problem #151

@MuntzMathias

Description

@MuntzMathias

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions