-
Notifications
You must be signed in to change notification settings - Fork 11.1k
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.5] fix a bug where model's delete method won't work if withCount is not empty. #22239
Conversation
Can you write a test with this testcase ? |
I added a test. This is the PR when withCount was introduced #19154 |
Eh, I don't like adding this seemingly random parameter to newQueryWithoutScopes. @themsaid do you have a more elegant solution? |
@taylorotwell the new approach he took is much cleaner, it's the same approach we take while preparing the update query. |
How does this affect MySQL See "Multi Table Deletes". |
Is it different than the test 'testDeleteWithJoinMethod' that is already written in DatabaseQueryBuilderTest.php ? |
@abdumu In the current code you remove the join bindings from the query, what happens if there's a delete query that uses joins? With this code it'll fail since the join bindings were removed. |
I didn't remove join bindings. |
Check https://github.com/laravel/framework/pull/22239/files#diff-bf9c2a600451a26e98eba7874fb841caR775 This is the same way you did it in prepareBindingsForUpdate, to make join bindings first. |
@abdumu yes and I believe it's wrong too, we'll need some integration tests similar to
Can you do that? |
I just found out that Grammar.php/compileDelete query doesn't respect joins and Laravel send joins I'm sorry I'm not sure I can test multiple engines with different approach. but I'll keep digging. |
Where are we with this? @themsaid? |
@taylorotwell I've tested it for MySQL and it works but I'm not sure about Postgres and sql server, they seems to have a unique syntax for delete statements with joins, MySQL needs the join bindings to be sorted first, postgres seems to require the where bindings first and then join bindings, and also seems that postgres doesn't remove select bindings. tl;dr |
A safe thing we could do is to return the exact input in |
@abdumu can you check my last comment regarding the method implementation in different grammars? |
withCount is meant for select queries, having counts in delete, update and then trying to remove the counts is absurd ! Since we are using newQueryWithoutScopes in performDeleteOnModel, save, ... Also, Sqlite Grammar is ignoring joins completely so no point of the integration tests ! (I might do some work later on this in another PR) |
Closing this since it's a possibly breaking change, please re-submit on master so we can prevent breaking other grammars. |
I've opened a PR with my suggested change in #22285 |
This fixes the bug that makes delete query receive two params instead of one if withCount array is not empty.
Before:
After: