It looks like you have a column called count , and PostgreSQL interprets this column name as a count aggregation function. Your SQL ends as follows:
SELECT "recommendations".* FROM "recommendations" INNER JOIN "approvals" ON "approvals"."recommendation_id" = "recommendations"."id" WHERE (approvals.count = 1 AND recommendations.user_id = 1)
The error message specifically points to approvals.count :
LINE 1: ...ecommendation_id" = "recommendations"."id" WHERE (approvals.... ^
I cannot reproduce this error in my PostgreSQL (9.0), but maybe you are using a different version. Try double quoting this column name in where :
Recommendation.joins(:approvals).where('approvals."count" = ? AND recommendations.user_id = ?', 1, current_user.id)
If this changes something, I would recommend renaming your approvals.count column to another so that you no longer have to worry about it.
source share