Skip to content

Commit

Permalink
Merge pull request #5711 from laravel/revert-5703-add_joins_to_delete
Browse files Browse the repository at this point in the history
Revert "deleting from eloquent model will work with joins"
  • Loading branch information
taylorotwell committed Sep 11, 2014
2 parents d57b430 + b97053d commit c2b34d2
Show file tree
Hide file tree
Showing 2 changed files with 3 additions and 25 deletions.
11 changes: 1 addition & 10 deletions src/Illuminate/Database/Query/Grammars/Grammar.php
Original file line number Diff line number Diff line change
Expand Up @@ -667,16 +667,7 @@ public function compileDelete(Builder $query)

$where = is_array($query->wheres) ? $this->compileWheres($query) : '';

if (isset($query->joins))
{
$joins = ' '.$this->compileJoins($query, $query->joins);
}
else
{
$joins = '';
}

return trim("delete $table from {$table}{$joins} $where");
return trim("delete from $table ".$where);
}

/**
Expand Down
17 changes: 2 additions & 15 deletions tests/Database/DatabaseQueryBuilderTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -936,29 +936,16 @@ public function testUpdateMethodRespectsRaw()
public function testDeleteMethod()
{
$builder = $this->getBuilder();
$builder->getConnection()->shouldReceive('delete')->once()->with('delete "users" from "users" where "email" = ?', array('foo'))->andReturn(1);
$builder->getConnection()->shouldReceive('delete')->once()->with('delete from "users" where "email" = ?', array('foo'))->andReturn(1);
$result = $builder->from('users')->where('email', '=', 'foo')->delete();
$this->assertEquals(1, $result);

$builder = $this->getBuilder();
$builder->getConnection()->shouldReceive('delete')->once()->with('delete "users" from "users" where "id" = ?', array(1))->andReturn(1);
$builder->getConnection()->shouldReceive('delete')->once()->with('delete from "users" where "id" = ?', array(1))->andReturn(1);
$result = $builder->from('users')->delete(1);
$this->assertEquals(1, $result);
}

public function testDeleteWithJoinMethod()
{
$builder = $this->getBuilder();
$builder->getConnection()->shouldReceive('delete')->once()->with('delete "users" from "users" inner join "contacts" on "users"."id" = "contacts"."id" where "email" = ?', array('foo'))->andReturn(1);
$result = $builder->from('users')->join('contacts', 'users.id', '=', 'contacts.id')->where('email', '=', 'foo')->delete();
$this->assertEquals(1, $result);

$builder = $this->getBuilder();
$builder->getConnection()->shouldReceive('delete')->once()->with('delete "users" from "users" inner join "contacts" on "users"."id" = "contacts"."id" where "id" = ?', array(1))->andReturn(1);
$result = $builder->from('users')->join('contacts', 'users.id', '=', 'contacts.id')->delete(1);
$this->assertEquals(1, $result);
}


public function testTruncateMethod()
{
Expand Down

0 comments on commit c2b34d2

Please sign in to comment.