Replies: 5 comments 1 reply
-
Instead you can do: $ids = User::join('address', 'user.address_id', '=', 'address.id')
->where('user.type', 'standard')
->limit(5)
->pluck('user.id');
User::whereIn('id', $ids)->delete(); |
Beta Was this translation helpful? Give feedback.
-
Shouldn't it be prevented then? Throw an error or something? (It seems like this is not even mentioned in the documentation) |
Beta Was this translation helpful? Give feedback.
-
The issue is from the database driver. So, it may not be prevented in framework level. Also, preventing it in framework level has a possibility of breaking existing applications. And since it is a community-based framework, you can submit a PR in https://github.com/laravel/docs and mention it there. |
Beta Was this translation helpful? Give feedback.
-
I am not sure what @achyutkneupane means by an issue on the "database driver" (which driver? PHP's But if you are using MySQL as your DBMS, it doesn't allow
Source: https://dev.mysql.com/doc/refman/8.0/en/delete.html#id266747 I am not sure if this limitation is present in other DBMS. |
Beta Was this translation helpful? Give feedback.
-
I was referring to the |
Beta Was this translation helpful? Give feedback.
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
-
Laravel Version
12.19.3
PHP Version
8.4
Database Driver & Version
No response
Description
It seems like the
delete()
not always respectlimit().
Steps To Reproduce
Example:
User::where('type', 'standard')->limit(5)->delete(); //deletes 5 users
User::join('address', 'user.address_id', '=', 'address.id')->where('user.type', 'standard')->limit(5)->delete(); //deletes all users matching the where condition
Beta Was this translation helpful? Give feedback.
All reactions