与default_scope连接关系时的PG :: SyntaxError

时间:2014-05-13 07:47:59

标签: ruby-on-rails ruby activerecord ruby-on-rails-4

Ruby on Rails 4.0.1。

Church,Campus,Households类由STI从Group类继承。

组类有default_scope

scope :active, -> { where(active: true) }
default_scope active

这个

  

Church.last.campuses.joins(:户).to_sql

给出这样的sql:

SELECT "groups".* FROM "groups" INNER JOIN "groups" "households_groups" ON "households_groups"."parent_group_id" = "groups"."id" AND "households_groups"."type" IN ('Household') AND "groups"."type" IN ('Household'), "groups"."active" = 't' WHERE "groups"."active" = 't' AND "groups"."type" IN ('Campus') AND "groups"."parent_group_id" = $1

并导致错误:

PG::SyntaxError: ERROR:  syntax error at or near "="
LINE 1: ...roups"."type" IN ('Household'), "groups"."active" = 't' WHER...

在“groups”之前应该有“AND”而不是逗号。“active”。

有没有办法避免这个bug并保留default_scope?

0 个答案:

没有答案