There is a bug https://github.com/rails/arel/issues/531 in Rails 5.0 and
5.1 in Arel/ActiveRecord.
This commit converts arel based queries to their raw counterparts to
make the finder work in Rails 5.0.
These changes should be reverted when on Rails 5.2 as since that version
such queries work well again. See the bug link.