这个问题出现在 squeel 1.0.11 上。我已经提交了一个问题,但认为社区可能已经有了答案。
我的模型中同一个表有两个关系,我在两个不同范围的连接中使用这两个关系。
class Log < ActiveRecord::Base
attr_accessible :created_by_id, :updated_by_id
belongs_to :created_by, class_name: "User"
belongs_to :updated_by, class_name: "User"
scope :suggested,
joins{created_by}.
where{(created_by.can_admin_logs == false) |
(created_by.can_admin_logs == nil)}
scope :not_edited,
joins{updated_by}.
where{(updated_by.can_admin_logs == false) |
(updated_by.can_admin_logs == nil)}
end
当这些范围一起更改时,sql 不正确。
Log.suggested.not_edited.to_sql
SELECT "logs".* FROM "logs" INNER JOIN "users" ON "users"."id" = "logs"."created_by_id" INNER JOIN "users" "updated_bies_logs" ON "updated_bies_logs"."id" = "logs "."updated_by_id" WHERE (("users"."can_admin_logs" = 'f' OR "users"."can_admin_logs" IS NULL)) AND (("updated_bies_logs"."can_admin_logs" = 'f' OR "updated_bies_logs". “can_admin_logs”为空))
我已经修改了各种更改来解决updated_bies_logs
问题,但还没有找到解决方案。
1.0.11 的发行说明似乎解决了这个问题,但我更新了我的 gem,问题仍然存在。