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

Handle null relations ? #8

Open
jodou92 opened this issue Jun 5, 2020 · 1 comment
Open

Handle null relations ? #8

jodou92 opened this issue Jun 5, 2020 · 1 comment

Comments

@jodou92
Copy link

jodou92 commented Jun 5, 2020

Hello,

I am not sure it is an issue, but I'd like to discuss it with you.
In my application I have an OrderItem with a ManyToOne Relation with another Entity called Child.
An OrderItem can have 0 or 1 child defined.

Now, in my orderRepository, I want to get OrderItems with child and its parent data, so I tried this way :

$this->associationHydrator->hydrateAssociations($order, [
            'items',
            'items.concernedChild.parent',
]);

But as concernedChild may be null I get an exception for this line of AssociationHydrator :
$subjects = array_map([$this->entityManager->getUnitOfWork(), 'getEntityIdentifier'], $subjects);

I managed to get it work by adding a simple filter on the $subjects array like this :

$subjects = array_filter($subjects, function ($subject) {
       return $subject !== null;
});

What do you think ? is it normal that I get an Exception ? and is my solution valuable ?

Thanks !

@jodou92
Copy link
Author

jodou92 commented Jun 5, 2020

Oh I did not see this PR : https://github.com/SyliusLabs/AssociationHydrator/pull/4/files
But in fact it fixes my issue in a better way that I did.

Is the PR going to be merged ? As the AssociationHydrator class is "final", I have to duplicate the code in order to fix it.

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