Query with optional where clause, in or clause, generates wrong query #69

Closed
ktoso opened this Issue Nov 7, 2012 · 1 comment

Comments

Projects
None yet
2 participants
Contributor

ktoso commented Nov 7, 2012

Hey guys,
seems we encountered a bug in building a specific query, example bellow:

MyMeta
      .or(
        _.where(_.things in List(thing)),
        _.whereOpt(additionalThing))(_.additionalThings in List(_))
      )

Which generates such query (additionalThing = None):

... "$or": [ { "things" : { "$in" : [ "thingA"]}} , { }]},  ...

What we don't like here is the { } part in the or. We'd rather just have it left out.
This makes the query fetch the entire collection so we had to fallback to manual building of or if it's needed.

Cheers and thanks for the great lib :)
Konrad

Contributor

jliszka commented Nov 7, 2012

Aha, thanks! Will fix.

Regards,
Jason

On Wed, Nov 7, 2012 at 8:09 AM, Konrad Malawski notifications@github.comwrote:

Hey guys,
seems we encountered a bug in building a specific query, example bellow:

MyMeta
.or(
.where(.things in List(thing)),
.whereOpt(additionalThing))(.additionalThings in List(_))
)

Which generates such query (additionalThing = None):

... "$or": [ { "postal_codes" : { "$in" : [ "95206"]}} , { }]}, ...

What we don't like here is the { } part in the or. We'd rather just have
it left out.
This impacts index use so we had to fallback to manual building of or if
it's needed.

Cheers and thanks for the great lib :)
Konrad


Reply to this email directly or view it on GitHubhttps://github.com/foursquare/rogue/issues/69.

ktoso added a commit to ktoso/rogue that referenced this issue Dec 25, 2012

@jliszka jliszka closed this in b979c66 Dec 26, 2012

jliszka added a commit that referenced this issue Dec 26, 2012

Merge pull request #71 from ktoso/master
Resolves #69 - in which or(where, whereOpt(None)) creates a bad query

jliszka added a commit that referenced this issue Jun 17, 2013

resolves #69, a blank `{}` should not be included in or queries
This solves an edge case when you have an or(_.where, _.whereOpt(None))
which would before leave a blank `{}` in the query string, making misbehave.

I've added `isEmpty` to `AndCondition`, please let me know if you'd
rather keep it method-less, and we can find a better place for this
method (or don't introduce one at all?)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment