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.8] Fix DELETE queries with alias on SQLite #29164

Merged
merged 2 commits into from
Jul 15, 2019
Merged

[5.8] Fix DELETE queries with alias on SQLite #29164

merged 2 commits into from
Jul 15, 2019

Conversation

staudenmeir
Copy link
Contributor

DELETE queries with an alias don't work on SQLite:

DB::table('users as u')->join('posts', 'posts.user_id', '=', 'u.id')->delete();

// expected
delete from "users" as "u" where "rowid" in (
  select "u"."rowid" from "users" as "u"
  inner join "posts" on "posts"."user_id" = "u"."id"
)

// actual
delete from "users" as "u" where "rowid" in (
  select "users" as "u.rowid" from "users" as "u"
         ^^^^^^^^^^^^^^^^^^^^
  inner join "posts" on "posts"."user_id" = "u"."id"
)

Fixes #29141.

@driesvints
Copy link
Member

@staudenmeir thanks!

@taylorotwell
Copy link
Member

Conflicts here.

@staudenmeir
Copy link
Contributor Author

@taylorotwell Resolved.

@taylorotwell taylorotwell merged commit 4b0cdaf into laravel:5.8 Jul 15, 2019
@staudenmeir staudenmeir deleted the delete-alias branch July 15, 2019 23:40
@driesvints
Copy link
Member

@staudenmeir small tip: if you rebase your branch instead of merging you prevent the extra merge commit from being added. This keeps the commit history a little cleaner.

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.

Generated query for SQLite is incorrect when deleting records with JOIN and table aliases
3 participants