-1

How do I add another column to scope and still be able to call .count, .find, .where, etc.

 User.all.select('users.*,"one" as one').count

Result:

  (1.3ms)  SELECT COUNT(users.*,"one" as one) FROM "users"
Traceback (most recent call last):
        1: from (irb):7
ActiveRecord::StatementInvalid (PG::SyntaxError: ERROR:  syntax error at or near "as")
LINE 1: SELECT COUNT(users.*,"one" as one) FROM "users"
                                   ^
: SELECT COUNT(users.*,"one" as one) FROM "users"
user2012677
  • 5,465
  • 6
  • 51
  • 113

1 Answers1

-1
 User.all.select('users.*,"one" as one').count(:all)

and

 User.all.select('users.*,"one" as one').count(:id)

Both work because it specifies what the SQL code should count on.

user2012677
  • 5,465
  • 6
  • 51
  • 113