js-data-rethinkdb
js-data-rethinkdb copied to clipboard
Testing support 'containsArray' keyword in where clause
I'm testing the implementation of the keyword 'containsArray' in where clause. Find subarray value in array field
'containsArray': function _containsArray(r, row, field, value) {
return row(field).default([]).setIntersection(r.expr(value).default([])).count().eq(value.length);
}
where: {
tags: {
containsArray: ['tag1','tag2']
}
}
The problem with containsArray
is that it's ambiguous on whether it's ORing or ANDing together the values. You can already accomplish this with:
// OR them together
where: [
{ tags: { contains: 'tag1' } },
'or',
{ tags: { contains: 'tag2' } },
'or',
{ tags: { contains: 'tag3' } }
]
// AND them together
where: [
{ tags: { contains: 'tag1' } },
{ tags: { contains: 'tag2' } },
{ tags: { contains: 'tag3' } }
]
Note, this is with JSData 3.x and RethinkDBAdapter 3.x