Skip to content
This repository has been archived by the owner on Nov 11, 2020. It is now read-only.

Query builder improvements #128

Merged
merged 34 commits into from
Sep 2, 2013
Merged

Query builder improvements #128

merged 34 commits into from
Sep 2, 2013

Conversation

jmikola
Copy link
Member

@jmikola jmikola commented Aug 13, 2013

No description provided.

The Query object is immutable, so this shouldn't make a difference in practice.
jmikola added 18 commits August 14, 2013 14:58
This will require changes to ODM, as several of its tests expect this to access only $query['query'] contents.
Note: $pullAll only supports an array of values (no expressions), so it remains as-is.
The recursive merging in addManyToSet() dates back to: doctrine/mongodb-odm@59a2da0. This could be problematic if addManyToSet() was called multiple times with deep array values, as they could be merged together in PHP. The new behavior will just overwrite the existing value in $newObj, like other update operators.
MongoDB 2.4 deprecates the $pushAll operator in favor of $push with $each. Additionally, it adds support for $slice and $sort (only in combination with $each).
If the $each operator does not appear first, the $push argument will be considered a single value to append to the array field.
This changes the public API for in/notIn and removes the array cast in notIn (behavior change); however, the methods are now consistent.

Other methods that take a single scalar type can use casting to sanitize their input.
geoNear commands against 2dsphere indexes require the "spherical" option to be true, so we can infer its default based on whether or not the "near" option is GeoJSON (in both Builder and Collection).
This makes map() as functional as mapReduce(), apart from setting the "reduce" option.
@jwage
Copy link
Member

jwage commented Aug 15, 2013

👍

These are not accessed in Query unless the query type is appropriate, and the initializer methods for those query types already create the expected fields.
Also renamed the option, which is set in the query array.
Builder now initializes a much smaller array, which only contains the default type. The array structure will grow as methods are called. In turn, Query only expects the "type", "query", and possibly "newObj" fields to exist. All others are checked for existence before access.

geoNear options were moved into an "options" array, which is now consistent with mapReduce and group.

A subtle behavioral change is that defaults for update operations and cursor options will no longer be applied unless explicitly set by the user. This should not be a problem, as the Builder defaults were consistent with those in the driver itself.
Builder::hint() is only useful for setting a cursor hint (not related to ODM's UnitOfWork hints), so there is no reason to track multiple calls and apply them all to the cursor in Query::prepareCursor().
This is consistent with what is already done for geoNear commands.
This can be removed in 2.0. It's currently a bit clumsy as the names for some of these types are arbitrary. It would be preferable to use constants.
Changed to avoid calling execute() and throw BadMethodCallException immediately if the query type is not documented as returning an Iterator. If the query type should return an Iterator, we execute it and then throw UnexpectedValueException if it does not.
jmikola added a commit that referenced this pull request Sep 2, 2013
@jmikola jmikola merged commit d13aab0 into master Sep 2, 2013
@jmikola jmikola deleted the query-builder branch September 2, 2013 18:15
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants