Browse files

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?)
  • Loading branch information...
1 parent 20eb932 commit b979c669d8b0adfd1b65b1564c61d27a5062e595 @ktoso ktoso committed Dec 25, 2012
View
4 rogue-core/src/main/scala/com/foursquare/rogue/MongoHelpers.scala
@@ -6,7 +6,9 @@ import com.mongodb.{BasicDBObjectBuilder, DBObject}
import scala.collection.immutable.ListMap
object MongoHelpers extends Rogue {
- case class AndCondition(clauses: List[QueryClause[_]], orCondition: Option[OrCondition])
+ case class AndCondition(clauses: List[QueryClause[_]], orCondition: Option[OrCondition]) {
+ def isEmpty: Boolean = clauses.isEmpty && orCondition.isEmpty
+ }
case class OrCondition(conditions: List[AndCondition])
View
1 rogue-core/src/main/scala/com/foursquare/rogue/QueryHelpers.scala
@@ -145,6 +145,7 @@ object QueryHelpers {
def orConditionFromQueries(subqueries: List[Query[_, _, _]]) = {
MongoHelpers.OrCondition(subqueries.flatMap(subquery => {
subquery match {
+ case q: Query[_, _, _] if q.condition.isEmpty => None
case q: Query[_, _, _] => Some(q.condition)
case _ => None
}

0 comments on commit b979c66

Please sign in to comment.