diff --git a/system/Model.php b/system/Model.php index a7f9607e5c89..e02bbe68cd3d 100644 --- a/system/Model.php +++ b/system/Model.php @@ -473,9 +473,13 @@ public function first() // Some databases, like PostgreSQL, need order // information to consistently return correct results when there is group by - if (! empty($this->QBGroupBy) && empty($builder->QBOrderBy) && ! empty($this->primaryKey)) + // except when soft delete is enabled + if (empty($builder->QBOrderBy) && ! empty($this->primaryKey)) { - $builder->orderBy($this->table . '.' . $this->primaryKey, 'asc'); + if (! empty($this->QBGroupBy) || $this->tempUseSoftDeletes === true) + { + $builder->orderBy($this->table . '.' . $this->primaryKey, 'asc'); + } } $row = $builder->limit(1, 0)