Search code examples
breezepredicateone-to-one

Breeze Predicate on on to zero/or Related Porperty


How to filter an entity to only get records where the related property (one to zero/one relationship) is not null? From the docs, i get this to filter cutomers with no orders:

var p = Predicate.create("orders", "any", "id", "!=", null).not();
var query = EntityQuery.from("Customers").where(p);

where customer and orders have a one to zero or many relationship. How can i perform the same operation if customer and order had a one to zero/one relationship?


Solution

  • While addressing the count of a collection is supported by OData 4, breeze does not yet support OData 4, so you cannot do this with a predicate.

    I see a couple alternatives:

    1. Include a property on the entity from the server that tells you whether the customer has zero or one order, then create a predicate from that.
    2. Filter the data on the client-side after retrieving it from the server.