So this is still 0 (n), but it is 1n, not 2n. To avoid unnecessary selections, I solved this problem using the user repository class and the doctrine query builder as follows:
namespace BRS\PageBundle\Repository; use Doctrine\ORM\EntityRepository; class ContentRepository extends EntityRepository { public function reorder($content) { $em = $this->getEntityManager(); $count = 0; foreach($content as $i => $content_id){ $q = $em->createQuery('update BRSPageBundle:Content c set c.display_order = ?1 where c.id = ?2') ->setParameter(1, $i) ->setParameter(2, $content_id); $count += $q->execute(); } return $count; } }
let's say that you have an array of content identifiers, for example:
$content = array(23,12,8,4);
Then you can quite simply update the order from your controller:
$count = $this->getRepository('BRSPageBundle:Content')->reorder($content);
semateos
source share