1

I am wanting to iterate through all database entries and replace the index with a new integer based on an array sent to the server in a form post.

So far I have this:

 /**
     * Order
     *
     * @Route("/order", name="cms_journey_order")
     * @Method("POST")
     * @Template()
     */
    public function orderAction(Request $id)
    {

        $em = $this->getDoctrine()->getManager();

        $entities = $em->getRepository('LVBundle:Journey')->getById($id);

        // SOME LOOP GOES HERE TO ADD NEW INDEX TO $ID FIELD IN DB

        return array(
            'entities' => $entities,
        );
    }

I guess I need something like a for loop, where each entity is rewritten?

JohnRobertPett
  • 1,133
  • 4
  • 21
  • 36
  • 1
    Ok, no, bad idea, don't do updates in a loop, it will murder your database. [Do multiple updates in one query](http://stackoverflow.com/questions/20255138/sql-update-multiple-records-in-one-query). – Andrei Jul 01 '15 at 09:10
  • Thanks for the comment, but this is in Symfony, so doesn't really require directly writing the SQL - this is my main issue here. – JohnRobertPett Jul 01 '15 at 11:07
  • Symfony or not, everything eventually leads to generating some kind of sql when it comes to doctrine. @Andrew made a valid point, so you should really try writing custom DQL according to your needs. Take a look at batch processing chapter - http://doctrine-orm.readthedocs.org/en/latest/reference/batch-processing.html – Artamiel Jul 01 '15 at 11:50

0 Answers0