help with symfony query 3

0

Hello it turns out that I'm working on a project in symfony 3.3 and I have an Entity that has fields like

  • title (string)
  • auto (boolean)
  • createdAt (datetime)
  • ftope (datetime), this last is a deadline

and I would like to make a query in my repository that I returned the elements with an order similar to this

first those that have the auto field in true if the deadline is still valid and then the rest in descending order by the createdAt date

can all this be done in a single query or should that be done in the view with twig?

    
asked by Juan Miguel Perez Fauria 26.01.2018 в 21:13
source

2 answers

0

You can use in the query

$qb->addOrderBy('column1', 'ASC')
   ->addOrderBy('column2', 'ASC')
   ->addOrderBy('column3', 'DESC');

as if it were a normal sql query

    
answered by 04.02.2018 в 17:45
0

Try this

//crear el query

//agregar lo siguiente
$query
    ->addSelect("IF(DATE(NOW()) < ftope AND AUTO, 0, 1)  AS HIDDEN ORDEN");
    ->orderBy('ORDEN', 'ASC');
    ->orderBy('createdAt', 'DESC');

There is a reference to hidden columns here and here

    
answered by 04.02.2018 в 18:19