sfDoctrineRestGeneratorPlugin icon indicating copy to clipboard operation
sfDoctrineRestGeneratorPlugin copied to clipboard

Sorting by more than one field is not possible from generator.yml

Open nederdirk opened this issue 11 years ago • 1 comments

If you want to sort on different fields (e.g. begintime ASC, endtime ASC) this is not possible. One way to do this is by overriding the query method:

    public function query($params)
    {
        if (!array_key_exists('sort_by', $params)) {
            $q = parent::query($params);
            return $q->orderBy('endtime ASC');
        }
        return parent::query($params);
    }

with [begintime, asc] in the sort_default field in generator.yml.

A method that would be better is to allow multiple fields to sort by (by default):

sort_default:
  - { field: begintime, order: asc }
  - { field: endtime, order: asc }

However, this would break backwards compatibility. I would be glad to implement this.

nederdirk avatar Dec 11 '13 11:12 nederdirk

@nederdirk, just go ahead, this feature seems to be useful and is a good idea. Thanks by the way for your work :-)

xavierlacot avatar Jan 01 '14 22:01 xavierlacot