Skip to content

Commit

Permalink
Merge pull request #29313 from staudenmeir/pgsql-delete
Browse files Browse the repository at this point in the history
[5.8] Fix DELETE queries with joins on PostgreSQL
  • Loading branch information
taylorotwell authored Jul 29, 2019
2 parents 0c3d547 + 5b99ece commit af46990
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 2 deletions.
4 changes: 2 additions & 2 deletions src/Illuminate/Database/Query/Grammars/PostgresGrammar.php
Original file line number Diff line number Diff line change
Expand Up @@ -400,9 +400,9 @@ protected function compileDeleteWithJoins($query, $table)
return $this->wrapTable($join->table);
})->implode(', ');

$where = count($query->wheres) > 0 ? ' '.$this->compileUpdateWheres($query) : '';
$where = $this->compileUpdateWheres($query);

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

/**
Expand Down
5 changes: 5 additions & 0 deletions tests/Database/DatabaseQueryBuilderTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -2183,6 +2183,11 @@ public function testDeleteWithJoinMethod()
})->where('name', 'baz')
->delete();
$this->assertEquals(1, $result);

$builder = $this->getPostgresBuilder();
$builder->getConnection()->shouldReceive('delete')->once()->with('delete from "users" USING "contacts" where "users"."id" = "contacts"."id"', [])->andReturn(1);
$result = $builder->from('users')->join('contacts', 'users.id', '=', 'contacts.id')->delete();
$this->assertEquals(1, $result);
}

public function testTruncateMethod()
Expand Down

0 comments on commit af46990

Please sign in to comment.