/** * Builds a generic ORDER BY clasue based on the model's state */ protected function _buildQueryOrder(DatabaseQuerySelect $query) { $sort = $this->getState()->sort; $direction = strtoupper($this->getState()->direction); if ($sort) { $query->order($this->getTable()->mapColumns($sort), $direction); } if (array_key_exists('ordering', $this->getTable()->getColumns())) { $query->order('tbl.ordering', 'ASC'); } }