This repository has been archived by the owner on Mar 30, 2022. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 213
Join with where block and default is broken. #361
Comments
I have been using squeel long time already. So I thought that it is Active Record issue. But after I made test for it I reconsidered it as it didn't occur if squeel wasn't required.
If require 'squeel' is included the following exception will be thrown:
|
Sign up for free
to subscribe to this conversation on GitHub.
Already have an account?
Sign in.
Squeel appears to be broken when defining an association with a
where
clause of typeString
, and adefault_scope
on one of the models.I'm using rails 4.1.9, though I've seen it on other versions > 4 as well. Using squeel 1.2.3 and postgres.
Models
Code
Result
SQL
As you can see, the last conditional is not being added to the SQL correctly. We expect
AND (vehicles.id = 1)
but get, (vehicles.id = 1)
. My assumption is that this occurs becausevehicles.id = 1
is being added as a simple simple string. If we change the syntax to"vehicles.id" => 1
then everything works as expected.This only occurs when there is both a string based
where
scope block in the association definition, and when the association's model has adefault_scope
. The error occurs even when not using squeel syntax anywhere in the app.I've traced the problem to the
collapse_wheres
method, specifically in the final code block whereString
based where clauses are explicitly handled. String based where clauses are added toarel.where
but they are neverANDed
with the other groups. I'll add a pull request with what I think is a correct solution, though I will mention that I am not deeply versed in arel.Any input would be greatly appreciated.
The text was updated successfully, but these errors were encountered: