How to order a list of decimals in Doctrine

  doctrine, mysql, php

I’m trying to order data from my database of type decimal.

But it’s not ordering properly.

In my entity:

   /**
     * @ORMColumn(type="decimal", precision=10, scale=2)
     */
    private $price;

My query in my repository :

  public function orderByField($field, $order)
      {
          return $this->createQueryBuilder('a')
                      ->orderBy('a.' . $field, $order)
                      ->getQuery()
                      ->getResult();
      }

$field is the name of the field to sort and $order is either "ASC" or "DESC".

My function works well for string types but how do I make it work for decimal type fields ?

Source: Ask PHP

LEAVE A COMMENT