serek | 25 Sep 16:44 2011
Picon

How do you handle export to json entities with circular references?

Hi

I have a Car entity with One-to-many relation to CarType entity.

I need retrieve some cars from DB and convert their data into json. So
I did:

$em = $this->get('doctrine.orm.entity_manager');
$cars = $em->getRepository('Tcs\XXXBundle\Entity\Car')->findAll();
$serializer = new Serializer(array(new GetSetMethodNormalizer()),
array('json' => new JsonEncoder()));
$json = $serializer->serialize($cars, 'json');

unfortunately I got:
"Fatal error: Maximum function nesting level of '100' reached,
aborting! in"

Ok, Car points to CarType, which points back to Car.

I found some working solution for this problem:
- add  toArray method to Car entity
- assign null as CarType references before call serialize
- use QueryBuilder and hydrate to array instead of objects
it works but I need something more generic, what works for all cases
and is not needed to update after every change in entity.

How would you solve this problem?
Is there any way to specified how deep in references should Normalizer
go?

(Continue reading)

Johan Dufour | 20 Dec 10:52 2011
Picon

Re: How do you handle export to json entities with circular references?

Hi Serek,


Same problem here. A solution would be welcomed.

Johan.

--
If you want to report a vulnerability issue on symfony, please send it to security at symfony-project.com
 
You received this message because you are subscribed to the Google
Groups "Symfony2" group.
To post to this group, send email to symfony2-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org
To unsubscribe from this group, send email to
symfony2+unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org
For more options, visit this group at
http://groups.google.com/group/symfony2?hl=en

Gmane