PG::DatatypeMismatch:错误:AND 的参数必须是布尔类型,而不是整数类型

Can*_*yer 2 ruby-on-rails

我使用 MySQL 在 Rails 中开发了一个基本应用程序。我正在转换为 PostgreSQL 数据库。我完成了数据库设置,除了有many to many关系的查询之外,大多数查询都可以工作。

我的模型看起来像这样:

User has_and_belongs_to_many :locations

Location has_and_belongs_to_many :users
Run Code Online (Sandbox Code Playgroud)

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

location = current_user.locations.find_by(cookies[:current_location])
Run Code Online (Sandbox Code Playgroud)

产生这个错误:

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
Run Code Online (Sandbox Code Playgroud)

提前致谢。

jvi*_*ian 5

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

location = current_user.locations.find_by(current_location: cookies[:current_location])
Run Code Online (Sandbox Code Playgroud)