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

FindAndCountAll generates wrong query for count #229

Closed
lafriks opened this issue Oct 19, 2021 · 2 comments · Fixed by #231
Closed

FindAndCountAll generates wrong query for count #229

lafriks opened this issue Oct 19, 2021 · 2 comments · Fixed by #231
Labels
bug Something isn't working

Comments

@lafriks
Copy link
Contributor

lafriks commented Oct 19, 2021

When selecting total count soft-deleted record condition is not added to count select query.

From log:

time="2021-10-19T17:08:05+03:00" level=info msg=Query args="[false]" fields.time="560.007µs" pid=680 rowCount=1 sql="SELECT * FROM \"clients\" WHERE \"deleted\"=$1 LIMIT 20;"
time="2021-10-19T17:08:05+03:00" level=info msg=Query args="[]" fields.time="420.81µs" pid=680 rowCount=1 sql="SELECT count(*) AS result FROM \"clients\";"
@lafriks lafriks changed the title FindAndCountAll generates invalid query for count FindAndCountAll generates wrong query for count Oct 19, 2021
@Fs02 Fs02 added the bug Something isn't working label Oct 19, 2021
@Fs02
Copy link
Member

Fs02 commented Oct 19, 2021

Thanks for the report, this bug happens because this line:

return r.aggregate(cw, query, "count", "*")

is not wrapping the query withDefaultScope, looks like modfying the line to be: return r.aggregate(cw, r.withDefaultScope(col.data, query, true), "count", "*") is enough to fix this

@lafriks
Copy link
Contributor Author

lafriks commented Oct 19, 2021

That was fast, thanks :)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants