- Maybe just use simple variable assignment.

- If you want to persist an entity into the database, use $em->persist(), not 
$em->merge().

- You only have to call $em->persist() to _update_ an entity if you changed the 
Change Tracking Policy to "Deferred Explicit".

    $position = 1;

    foreach (array_keys($genres) as $genreId) {
        $genre = $this->getRepository()->findOneById($genreId);
        $genre->setRanking($position);
        $this->getObjectManager()->persist($genre);  // only for "Deferred 
Explicit"

        $position++;
    }

--  
Jasper N. Brouwer
(@jaspernbrouwer)


On 21 October 2014 at 22:48:50, Antenne ([email protected]) wrote:
> I have the following code in a service:
>  
> $position = 1;
>  
> // Update all genres with new position
> foreach ($genres as $key => $value)
> {
> ${"genre" . $position} =
> $this->getRepository()->findOneById($key);
> ${"genre" . $position} ->setRanking($position);
> $this->getObjectManager()->merge(${"genre" . $position} );
>  
> ++$position;
> }
> $this->getObjectManager()->flush();
>  
>  
> Every time I call it two need to be updated, however it only updates the
> first, even though I pass the right arguments.
> What could I be doing wrong here?
>  
> I thought it might have to do with the reference, so I dynamically assignes
> variable names in order to prevent that isssue.
> But still the second object isn't updated.
>  
> Could someone please give me an insight?
>  
> Thanks.


-- 
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