PG :: DatatypeMismatch:ERROR:AND的参数必须是boolean类型,而不是类型integer

时间:2018-03-23 21:47:31

标签: ruby-on-rails

我使用MySQL在Rails中开发了一个基本应用程序。我转换为PostgreSQL数据库。我得到了数据库设置,除了一个many to many关系之外,我的大部分查询都有效。

我的模特看起来像这样:

User has_and_belongs_to_many :locations

Location has_and_belongs_to_many :users

但是,当我执行这行代码时,我收到以下错误:

location = current_user.locations.find_by(cookies[:current_location])

产生此错误:

PG::DatatypeMismatch: ERROR:  argument of AND must be type boolean, not type integer
LINE 1: ...n_id" WHERE "locations_users"."user_id" = $1 AND (1) LIMIT $...
                                                         ^
: SELECT  "locations".* FROM "locations" INNER JOIN "locations_users" ON "locations"."id" = "locations_users"."location_id" WHERE "locations_users"."user_id" = $1 AND (1) LIMIT $2

提前致谢。

1 个答案:

答案 0 :(得分:3)

find_by需要一个或多个键值对。例如:

location = current_user.locations.find_by(current_location: cookies[:current_location])