Rails Postgres HSTORE:PG :: InternalError:ERROR:位置1处'='附近的语法错误

时间:2015-02-24 17:38:43

标签: ruby-on-rails postgresql postgresql-9.1 rails-postgresql hstore

我正在尝试使用false执行where(),而是像执行查询一样执行它:

PG::InternalError: ERROR:  Syntax error near '=' at position 1
LINE 1: ..."subject_users"."subject_id" = $1 AND (languages @> ' => 1')
                                                           ^
: SELECT DISTINCT COUNT(DISTINCT "users"."id") FROM "users" INNER JOIN 
"subject_users" ON "users"."id" = "subject_users"."user_id" WHERE 
"subject_users"."subject_id" = $1 AND (languages @> '

首先,我检查是否定义了参数:

langs = defined?(params[:languages]).nil? ? false : "languages @> '#
{params[:languages]} => 1'"

然后我根据主题和语言过滤掉用户,如果没有选择,则评估为false并返回该主题的所有用户。

@subject_users = Subject.includes(:users)
    .where(name: params[:subject_type]).first.users
    .where(langs)

0 个答案:

没有答案