Hi my code now looks like this:

public function sortGenres(array $genres)
    {
        $position = 1;

        // Update all genres with new position
        
        foreach (array_keys($genres) as $genreId)
        {
            $genre = $this->getRepository()->findOneById($genreId);
           
            if ($genre->getRanking() !== $position)
            {
                $genre->setRanking($position);
                $this->getObjectManager()->persist($genre);
            }

            ++$position;
        }
        $this->getObjectManager()->flush();
    }

So only two objects need to be updated because they changed position.
It updates the first with the new position, but somehow the second is not 
updated even though while debugging I see the position changed,
In the database however it remains the old position.
I even tried it without the persist like Jasper mentioned. I checked the 
code $genre->setRanking($position); is only called twice and correctly, but 
the second time is not stored in the database.

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