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

And() & Or() override inner Cond elements relationship #280

Closed
c2h5oh opened this issue Oct 20, 2016 · 1 comment
Closed

And() & Or() override inner Cond elements relationship #280

c2h5oh opened this issue Oct 20, 2016 · 1 comment

Comments

@c2h5oh
Copy link
Contributor

c2h5oh commented Oct 20, 2016

cond1 := db.Cond{"col1": "val1", "col2": "val2"}
cond2 := db.Cond{"col3": "val3"}

q.Where(db.Or(cond1, cond2))

expected:
WHERE (col1 = val1 AND col2 = val2) OR (col3 = val3)

actual
WHERE ((col1 = val1 AND col2 = val2 OR col3 = val3))

The same happens with And

xiam added a commit that referenced this issue Oct 21, 2016
@xiam xiam closed this as completed in #282 Oct 21, 2016
xiam pushed a commit that referenced this issue Oct 21, 2016
Add default AND join within Or. Closes #280
@xiam
Copy link
Member

xiam commented Oct 21, 2016

If you want to be explicit about this (and to preserve condition order) use:

q.Where(db.Or(
  db.And(
    db.Cond{"col1": "val1"},
    db.Cond{"col2": "val2"},
  ),
  db.And(
    db.Cond{"col3": "val3"},
  ),
))

xiam pushed a commit that referenced this issue Nov 24, 2016
Add default AND join within Or. Closes #280
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