How can I create a dql query to the database in SonataAdmin . I have a mySQL query, I need to translate it into dql , or somehow use it in this format, but I don’t know how

 SELECT ca.id, cu.card AS cu_id FROM card ca LEFT OUTER JOIN customer cu ON ca.id = cu.card WHERE cu.id IS NULL 
  • In DQL, the binding conditions are not written as ON clause, but as WITH clause: SELECT card.id, customer.card AS cu_id FROM card LEFT JOIN customer WITH card.id = customer.card WHERE customer.id IS NULL
  • understood thanks. - Maxim Strutinskiy

1 answer 1

It turned out to do:

  ->add( 'card', EntityType::class, [ 'required' => true, 'class' => 'MainBundle:Card', 'multiple' => false, 'query_builder' => function (EntityRepository $er) { return $er->createQueryBuilder('ca') ->select('ca') ->leftJoin('MainBundle\Entity\Customer', 'cu', 'WITH', 'ca.id = cu.card') ->where('cu.id IS NULL') ->groupBy('ca.id'); }, ] )