Search code examples
jsonodatabreeze

How to create a json query in with any() in Breezejs


I am trying to use this json predicate in Breeze:

predicate.push({
        or: [
            { not: { relocationStates: { any: {} } } },
            { relocationStates: { any: { "state.id": { "eq": 11 } } } }
        ]
    });

The purpose of not: {relocationStates: { any: {}}} is to include all items with empty list of relocationStates.

This should create a odata URL as follows:

$filter=(not RelocationStates/any()) or (RelocationStates/any(x1: (x1/State/Id eq 11)))

The above oData URL works fine, but breezejs is unable to create the URL and errors with:

TypeError: Cannot read property 'key' of null

Is it possible to create a json query in Breezejs that will return all items where the list of submitems is empty?


Solution

  • This appears to be a bug. I've created an issue for it in Breeze. You can expect a fix in the next release.

    A crude workaround would be to put in some clause that is always true for relocationStates, e.g.

    { not: { relocationStates: { any: { "id": { "ne": null } } } } }