Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[5.4] SqlServer join on delete #16618

Merged
merged 4 commits into from
Dec 4, 2016
Merged

[5.4] SqlServer join on delete #16618

merged 4 commits into from
Dec 4, 2016

Conversation

fernandobandeira
Copy link
Contributor

@fernandobandeira fernandobandeira commented Dec 1, 2016

This PR add support for join when deleting records using SqlServer, following the logic used on the MySQL grammar.

Example of the result:

delete [users] from [users] inner join [contacts] on [users].[id] = [contacts].[id] where [users].[id] = 1

Refs #16573

@fernandobandeira
Copy link
Contributor Author

fernandobandeira commented Dec 1, 2016

Also fixed a bug where using the join and calling the delete method passing an ID would throw an ambiguous error, ppl shouldn't do that but it's fixed just in case...

@@ -2247,7 +2247,7 @@ public function delete($id = null)
// the ID to allow developers to simply and quickly remove a single row
// from their database without manually specifying the where clauses.
if (! is_null($id)) {
$this->where('id', '=', $id);
$this->where($this->from.'.id', '=', $id);
Copy link
Member

@taylorotwell taylorotwell Dec 1, 2016

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Does this syntax cause any problems when you do a delete without a join? Does it care that you specify the table name in that case? We would need to verify that across all drivers.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yep, we need to verify that to be sure, it shouldn't cause any problems, but we should verify it just in case. I'll gather some feedback...

Copy link
Contributor Author

@fernandobandeira fernandobandeira Dec 1, 2016

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I've tested online on http://sqlfiddle.com/ and it works for all drivers it doesn't care for the table name at all...

@taylorotwell taylorotwell merged commit 5387746 into laravel:master Dec 4, 2016
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants