diff --git a/src/Illuminate/Database/Query/Grammars/MySqlGrammar.php b/src/Illuminate/Database/Query/Grammars/MySqlGrammar.php index f6583b2ae360..fbcad2775db2 100755 --- a/src/Illuminate/Database/Query/Grammars/MySqlGrammar.php +++ b/src/Illuminate/Database/Query/Grammars/MySqlGrammar.php @@ -197,14 +197,14 @@ public function compileDelete(Builder $query) $sql = trim("delete $table from {$table}{$joins} $where"); } else { $sql = trim("delete from $table $where"); - } - if (isset($query->orders)) { - $sql .= ' '.$this->compileOrders($query, $query->orders); - } + if (isset($query->orders)) { + $sql .= ' '.$this->compileOrders($query, $query->orders); + } - if (isset($query->limit)) { - $sql .= ' '.$this->compileLimit($query, $query->limit); + if (isset($query->limit)) { + $sql .= ' '.$this->compileLimit($query, $query->limit); + } } return $sql; diff --git a/tests/Database/DatabaseQueryBuilderTest.php b/tests/Database/DatabaseQueryBuilderTest.php index 280e0bbb210f..ec6033e0d89a 100755 --- a/tests/Database/DatabaseQueryBuilderTest.php +++ b/tests/Database/DatabaseQueryBuilderTest.php @@ -1217,18 +1217,23 @@ public function testDeleteMethod() $builder->getConnection()->shouldReceive('delete')->once()->with('delete from "users" where "id" = ?', [1])->andReturn(1); $result = $builder->from('users')->delete(1); $this->assertEquals(1, $result); + + $builder = $this->getMySqlBuilder(); + $builder->getConnection()->shouldReceive('delete')->once()->with('delete from `users` where `email` = ? order by `id` asc limit 1', ['foo'])->andReturn(1); + $result = $builder->from('users')->where('email', '=', 'foo')->orderBy('id')->take(1)->delete(); + $this->assertEquals(1, $result); } public function testDeleteWithJoinMethod() { $builder = $this->getMySqlBuilder(); $builder->getConnection()->shouldReceive('delete')->once()->with('delete `users` from `users` inner join `contacts` on `users`.`id` = `contacts`.`id` where `email` = ?', ['foo'])->andReturn(1); - $result = $builder->from('users')->join('contacts', 'users.id', '=', 'contacts.id')->where('email', '=', 'foo')->delete(); + $result = $builder->from('users')->join('contacts', 'users.id', '=', 'contacts.id')->where('email', '=', 'foo')->orderBy('id')->limit(1)->delete(); $this->assertEquals(1, $result); $builder = $this->getMySqlBuilder(); $builder->getConnection()->shouldReceive('delete')->once()->with('delete `users` from `users` inner join `contacts` on `users`.`id` = `contacts`.`id` where `id` = ?', [1])->andReturn(1); - $result = $builder->from('users')->join('contacts', 'users.id', '=', 'contacts.id')->delete(1); + $result = $builder->from('users')->join('contacts', 'users.id', '=', 'contacts.id')->orderBy('id')->take(1)->delete(1); $this->assertEquals(1, $result); }