I've worked a bit more on this and finally managed to get an OData "any" query to work. It's quite the hack, since I'm constrained by the existing design:
// ExtendedODataV4Adaptor
import { ODataV4Adaptor, DataUtil, Predicate, Query } from '@syncfusion/ej2-data';
export class ExtendedODataV4Adaptor extends ODataV4Adaptor {
onEachWhere(predicate: Predicate, query: Query, requiresCast?: boolean): string {
if (predicate.isComplex) {
var child = predicate.predicates[0];
// we've stuffed the collection/field combination into a pair of nested predicates.
// it's totally wrong, but there's no other way to get through the SyncFusion code
var operator = DataUtil.odBiOperator[predicate.operator];
return predicate.field + '/any(x: x/' + child.field + operator + predicate.value + ')';
}
return this.onPredicate(predicate, query, requiresCast);
}
}
// ExtendedQuery
import { Query, Predicate } from '@syncfusion/ej2-data';
export class ExtendedQuery extends Query {
constructor(from: string) {
super(from);
}
whereAny(collection: string, field: string, operator: string, value: string | number | boolean | Predicate | Date | Predicate[]) : ExtendedQuery {
operator = operator.toLowerCase();
var predicate = new Predicate(field, operator, value);
var container = new Predicate(collection, operator, value);
container.isComplex = true;
container.predicates = [predicate];
this.queries.push({ fn: 'onWhere', e: container });
return this;
}
}
// use it
this.query = new ExtendedQuery('Articles').whereAny('Tags', 'Id', 'equal', +this.tagId);
If this were to be implemented, I would suggest putting adding the whereAny() method to Query (and a corresponding whereAll()), and update ODataV4Adaptor to accept a Predicate that can generate the any/all queries. I've done my best given the existing constraints, and I'd rather not use this code since it's quite ugly. Please let me know if this is something you're likely to add in the future.
Thanks,
Brian