Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

incorrect SQL when filtering for multiple columns #5

Open
wgc-as opened this issue Aug 8, 2013 · 1 comment
Open

incorrect SQL when filtering for multiple columns #5

wgc-as opened this issue Aug 8, 2013 · 1 comment

Comments

@wgc-as
Copy link

wgc-as commented Aug 8, 2013

User.where(hair_color: 'brunette', figure: 'slim').or.where(hair_color: 'blonde', figure: 'normal')
SELECT users.* FROM users WHERE ((users.hair_color = 'brunette' AND users.figure = 'slim' OR users.hair_color = 'blonde' AND users.figure = 'normal'))

Need to wrap both sides of the OR in parenthesis. This is the SQL what I expect:

SELECT users.* FROM users WHERE ((users.hair_color = 'brunette' AND users.figure = 'slim') OR (users.hair_color = 'blonde' AND users.figure = 'normal'))

@daniel-illi
Copy link

The AND operator has precedence over the OR operator, so both your examples should give the same result.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants