-
Notifications
You must be signed in to change notification settings - Fork 19
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
Related Doctrine Entities fail with empty document? #3
Comments
Here's an additional snippet of the log output (gets really long otherwise)
|
This is a problem for Doctrine. It's design is flawed as it has circular references so it cannot be directly mapped. It will just blow up as you experienced. I tried solving this issue, but it requires setting a magic nesting number that will vary from case to case, so I decided not to include this solution until I find a way of fixing this. What I can recommend is creating objects to represent the resource that do not include so many references. For instance for an object having a reference to a first entity that has another reference, try redefing the "deepest entity" by removing any relationship to its parents or further relationships to other entities. |
If you or anyone reading this finds a solution, please post here |
This is a known issue: symfony/symfony#15627 And Dunglas tried patching it symfony/serializer@aae6fa7. Still doesn't fix the issue. I've got an idea on how to solve this, but I need some time to code it. |
Maybe can you try this trick to avoid circular references with Doctrine and display the entity's id when it is detected more than once: https://github.com/dunglas/DunglasApiBundle/blob/master/src/JsonLd/Serializer/ItemNormalizer.php#L63-L65 $this->setCircularReferenceHandler(function ($object) {
return $object->getId(); // It's better to use Doctrien metadata here to guess the id
}); We use it in API Platform and it works fine. |
@dunglas yeah I remember i send a tweet about it some months ago... just have to port it to my serializer, it's not JMS or Symfony's. |
Any news on this front? Or any orkarounds to make actual practical use of this? Because I really want to implement this |
@AlexandreKilian for the time being, breaking the cyclic dependency is the only way around, and that can be done by transforming all doctrine entities to objects of your own... I would need a day or two to dig into this properly, but this is a side project for me. I'm not writing APIs right now on my daily basis so I cannot spend as much time as I'd like to fix this. |
@nilportugues Sorry, that came accross the wrong way... I might have an idea of how to easily work around this issue with a custom repository class, but I'm still working on a few kinks |
@AlexandreKilian I'm actually trying to find myself some time to detect the cyclic dependencies and do something about it too. I'll keep you posted. |
@nilportugues Hi while waiting your fixing, i delete manually the closure from the clone of my entity Another solution: I tried to add the fetch mode "EAGER" on my entities to avoid the "Proxy class" which add the Closures, but i get a 500 error response from your bundle (with a blank page) Thank you ! |
@nilportugues Has anyone got a temporary fix of some way to work around this issue expect creating additional object? |
@svparijs you can create your DTOs and link them together manually and serialize that and the problem is gone. Actually it's a good practise to do so. |
@nilportugues it feels like a extra level of complexity and maintenance cost to add DTO's manually wiring them together. To make this package properly usable for Symfony/Doctrine this feature should be supported in my opinion. That being said I've been digging around in the code and it seems not to be easily implemented. I really would like this to work and would even be willing to sponsor a bit of the work. |
Can anybody post an example or gist of a hack on how to get around this? Would be greatly appreciated :) |
maybe using JsonSerializable in your entities you can something like this gist |
When I try to serialize a doctrine that has related entities, I get a blank 500 error and have to dig through my logs to figure out what happened.
It looks like it's boiling down to a nesting max depth error:
Any ideas on serializing related Doctrine entities?
The text was updated successfully, but these errors were encountered: