ernie/squeel — Issue #81: Squeel and .count problem in Rails 3.1
Author: tanelj
Created: 2011-11-24 12:57:00+00:00
State: open

Hi!
I have poblem when using Squeel (0.9.3) functions in queries and when there is a need to call .count for thes query (eg will_paginate (3.0.2) plugin).

Here is a simple example:

Employee.select{lastname.op('||', ', ').op('||', firstname).as(name)}.count

..gets error:

(0.3ms) SELECT COUNT(#) FROM "employees"
ActiveRecord::StatementInvalid: PGError: ERROR: syntax error at or near ":"
LINE 1: SELECT COUNT(#) FROM "...

And one will_paginate example:

Employee.select{lastname.op('||', ', ').op('||', firstname).as(name)}.paginate(:page => 1)

..gets:

Employee Load (0.7ms) SELECT "employees"."lastname" || ', ' || "employees"."firstname" AS name FROM "employees" LIMIT 50 OFFSET 0
(0.6ms) SELECT COUNT(#) FROM "employees"
ActiveRecord::StatementInvalid: PGError: ERROR: syntax error at or near ":"
LINE 1: SELECT COUNT(#) FROM "...

Is the problem in Rails or in Squeel?

I'm using postgre with Rails 3.1.1.