Fix count method to work with select statement.

Count method raises `ActiveRecord::StatementInvalid` if `select` method is used in Rails 4.1. This commit fixes will paginate and if work if `select` method is used.