0

Hello I worked with Symfony2 and Doctrine.

I want to order by my custom order with doctrine

SELECT id_product, pro_name FROM product ORDER BY FIELD(id_product,3,5,2)

I have tried

    $rang_1=array(3,5,2);
    $products = $em->getRepository('CompanyMyBundle:Product')->findBy(array('public' => 1,'idProduct'=>$rang_1), array('idProduct'=>$rang_1), 5);

AND

$sql = $em->createQuery("SELECT p FROM CompanyMyBundle:Product p WHERE l.public = 1 AND l.idProduct IN (".implode(',',$rang_1).")  ORDER BY FIELD(l.idProduct,".implode(',',$rang_1).")")->setMaxResults(5);

Any suggestion?

gastonnina
  • 559
  • 1
  • 10
  • 23

1 Answers1

0

I don't have any experience with the ORDER BY FIELD-expression, but have you seen this post already? Maybe it can help you out?

Seems like they've written a Doctrine 2 extension that handles the implementation for FIELD...

Community
  • 1
  • 1
UrGuardian4ngel
  • 568
  • 2
  • 7