So I called it both with and without the persist and still only the first
object is updated. Could there be a reason why second time round it is not
stored in the database?
Op dinsdag 21 oktober 2014 23:03:30 UTC+2 schreef Jàπ (Jasper N. Brouwer):
>
> - 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]
> <javascript:>) 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.