laravel/framework — pull request #4725 by daftspunk (2014-06-15 23:40:35+00:00)
Title: [Bug] Minor bug in MySQLGrammar logic

For your consideration, this global scope applies a default sort order:

```php
getModel();
$builder->orderBy('left_column');
}

public function remove(BuilderBase $builder)
{
$column = 'left_column';
$query = $builder->getQuery();

foreach ((array) $query->orders as $key => $order) {

if (!$this->isNestedTreeConstraint($order, $column))
continue;

unset($query->orders[$key]);
$query->orders = array_values($query->orders);
}
}

protected function isNestedTreeConstraint(array $order, $column)
{
return $order['column'] == $column;
}
}
```

This class is modelled after `SoftDeletingScope` and will **unset()** the `$orders` property of the query builder. This leaves an empty array.

Currently the logic checks using **isset()** on the property, which allows an empty array to pass through, resulting in a fragmented SQL statement.

```
update `table` set `title` = 'foobar' where `id` = 1 order by
```

I *could* update the scope to check if the array is empty and set it to `null`, but I believe this should be the frameworks responsibility to weed out these instances, hence is a bug in the logic.

Cheers