This problem is occurring on squeel 1.0.11. I have submitted an issue but thought the community may have an answer already.
I have two relationships to the same table in my model, and I'm using those two relationships in the join of two different scopes.
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
When those scopes are changed together, the sql is incorrect.
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" IS NULL))
I've tinkered with various changes to fix the updated_bies_logs
problem but haven't found a solution.
The release notes for 1.0.11 looked like they addressed this, but I updated my gem and the problem is still here.