-
Notifications
You must be signed in to change notification settings - Fork 1.5k
Issue with Soft-delete with orWhere #310
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
Labels
Comments
+1 |
I round the problem by this not too nice solution: Book::whereNotIn('user_id', [0])
->orWhere('user_id', $userId)
->orWhereIn('group_id', $groups)
->get() book.find{{"$and":[
{"deleted_at":null},
{"user_id":{"$nin":[0]}}
],
"$or":[
{"user_id":"541bf64fd4b41cda04fad053"},
{"group_id":{"$in":[1,2]}}
]}, []} The Original (not works): Book::where('user_id', $userId)
->orWhereIn('group_id', $groups)
->get() book.find({"$and":[
{"deleted_at":null},
{"user_id":"541bf64fd4b41cda04fad053"}
],
"$or":[
{"group_id":{"$in":[1,2]}}
]}, []) I also tried (not works): Book::orWhere('user_id', $userId)
->orWhereIn('group_id', $groups)
->get() book.find({"$or":[
{"deleted_at":null},
{"user_id":"541bf64fd4b41cda04fad053"},
{"group_id":{"$in":[1,2]}}
]}, []) |
Closed
+1 |
1 similar comment
+1 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
This issue was first reported in issue #43 but was closed and not resolved.
I have additional information re the issue to see if someone can help in the resolution.
Here's the query:
$row = Feature::where('name', '=', $input['name'])->orWhere('display_name', '=', $input['display_name'])->get();
We have a sql logger and this what is showing up in our log:
features.find({"$and":[{"deleted_at":null},{"name":"sun_roofs"}],"$or":[{"display_name":"Sun Roof"}]})
I then changed the query to:
$row = Feature::orWhere('name', '=', $input['name'])->orWhere('display_name', '=', $input['display_name'])->get();
The log shows:
features.find({"$or":[{"deleted_at":null},{"name":"sun_roofs"},{"display_name":"Sun Roof"}]})
In both queries, the "deleted_at" clause is not set properly - and it is resulting in wrong results being returned.
The text was updated successfully, but these errors were encountered: