Hey Parsifal,

Have you read the following article already?
https://github.com/doctrine/DoctrineModule/blob/master/docs/hydrator.md

Hydrators don't flush, it will update the data within the entity itself. 
You have to persist/flush the entity, depending on the state of the entity 
after hydrating. 

What do you mean by point 2? If you hydrate the same entity you will 
obviously overwrite it but if you take a new instance of your entity class 
it won't. Example:


use DoctrineModule\Stdlib\Hydrator\DoctrineObject as DoctrineHydrator;

$hydrator = new DoctrineHydrator($entityManager);

$exampleData = [
 0 => [
  'name' => 'Amsterdam'
 ],
 1 => [
  'name' => 'Paris'
 ],
 2 => [
  'name' => 'London'
 ]
];

$cities = [];
foreach ($exampleData as $data) {
 $city = new City();
 $city = $hydrator->hydrate($data, $city);
 $entityManager->persist($city);
 
 $cities[] = $city;
}

$entityManager->flush($cities);

PS: you dont need to flush an array containing the cities, but it gives you a 
bit more control over what you are flushing with the entityManager. Just 
persisting the entities and flushing will do if you don't change any other 
entities within your request else you will flush every entity managed by the 
EntityManager.

Hope this helps you.

Greetings,
Kwido



Op maandag 13 juli 2015 13:20:44 UTC+2 schreef Parsifal:
>
> Hi,
>
> I want to use DoctrineModule hydrator standalone without zend form just to 
> hydrate arrays.
>
> 1) Does it flush data too? Or do I need to call flush after hydrate?
> 2) If it does not flush itself, is it possible to hydrate data within a 
> foreach? Or the last data will be overwritten and only the last one will be 
> flushed?
>
> Thanks in advance,
>  

-- 
You received this message because you are subscribed to the Google Groups 
"doctrine-user" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to [email protected].
To post to this group, send email to [email protected].
Visit this group at http://groups.google.com/group/doctrine-user.
For more options, visit https://groups.google.com/d/optout.

Reply via email to