There is a bug in Rails 5.0 and 5.1 in Arel/ActiveRecord.
This MR converts arel based queries to their raw counterparts to make the finder work in Rails 5.0.
These changes should be reverted when we're on Rails 5.2 as since that version such queries work well again.
We've already faced this problem before.
Check if SQL queries are OK.
package-and-qa manual pipeline job)
Closes #47832 (closed)