This repository was archived by the owner on Mar 30, 2022. It is now read-only.

Description
Squeel 1.2.3 + AR 4.1.14 seems to generate invalid SQL when joining with an association that includes both simple condition and complex IN + OR condition.
E.g. a Parent
model with
has_many :complex_scoped_models, ->{ where(flag: true).where(field: ['test1', 'test2', nil]) }, class_name: 'Model'
will generate following SQL when doing Parent.all.joins(:complex_scoped_models).first
:
SELECT "parents".* FROM "parents" INNER JOIN "models" ON "models"."parent_id" = "parents"."id" AND "models"."flag" = 't', (("models"."field" IN ('test1', 'test2') OR "models"."field" IS NULL)) ORDER BY "parents"."id" ASC LIMIT 1
Note the comma after "models"."flag" = 't'
, when there should be another AND.
Same scope on the model itself (without an association) seems to be working.
I've put up a test bench for the issue, you can see full code and test at https://github.com/azhi/squeel_complex_scope_association_test.
PS: it looks similar to an error pointed by @vellotis in #361 (comment).