I have a model that contains a boolean attribute, Member can be admin. When I create a new Team I want to set this value to true for the Member that have created that Team. When I used SQLite it worked fine. The line that causes the error looks like this:
def set_admin
if self.members.admins.any? == false
self.members.first.update_attributes admin: true
end
end
My query (members.admins) that looks like this:
has_many :admins, -> { where("admin = 1") }, through: :members, source: :user
Note I have also tried:
has_many :admins, -> { where(admin = true) }, through: :members, source: :user
But I get the same error:
The full error message looks like this:
PG::UndefinedFunction: ERROR: operator does not exist: boolean = integer LINE 1: ...s" WHERE "members"."team_id" = $1 AND "members"."admin" = 1 ^ HINT: No operator matches the given name and argument type(s). You might need to add explicit type casts. : SELECT COUNT(*) FROM "members" WHERE "members"."team_id" = $1 AND "members"."admin" = 1
And I'n not sure how to solve it. Any ideas?