User.select(:id, :name, :email).count
. It threw a PG::UndefinedFunction
error. Using User.select(:id, :name, :email).size
worked instead.Out of curiosity, I did some digging. According the the ActiveRecord docs,
not all valid select expressions are valid count expressions. TheI also stumbled on an issue on rails Github issues page about this, and a very helpful comment from rafaelfranca explained that I can also use
specifics differ between databases. In invalid cases, an error from
the database is thrown.
count(:all)
.
No comments:
Post a Comment