lightblue-platform / lightblue-core

Document based data access layer framework
GNU General Public License v3.0
32 stars 23 forks source link

Association array query rewritten as "array contains" are incorrect #674

Open jewzaam opened 8 years ago

jewzaam commented 8 years ago

Entity A has _id. Entity B has referenceIds array with references to A._id.

Entity A has reference to B with

"Bs": {
    "entity": "B",
    "query": {
        "field": "$parent._id",
        "op": "$eq",
        "rfield": "referenceIds"        
    }
    "type": "reference",
    "versionValue": "1.0.0-SNAPSHOT"
},

But this is rewritten by query planner to:

    "query": {
        "array": "referenceIds",
        "contains": "$all",
        "values": [null]        
    }

I'll look at writing as elemMatch as the array contains syntax doesn't support referencing fields, only supports values (per documentation at least: https://jewzaam.gitbooks.io/lightblue-specifications/content/language_specification/query.html)

jewzaam commented 8 years ago

Actually not possible to use elemMatch, the array referenceIds is an array of simple types (strings).

I tried rewriting my reference query to hard code the array of values in the array contains query and the association works. But that's only as a PoC that such a query can work if it's rewritten correctly.

bserdar commented 8 years ago

The reference query should be $parent._id $in referenceIds, instead of $eq.

jewzaam commented 8 years ago

That may have been a mistake in my original post. This is not a pressing issue for any ongoing work, the metadata that needed this has been changing. If it comes up again I'll come up with a usable example to post here and test it out with the suggested change.