js-data-rethinkdb icon indicating copy to clipboard operation
js-data-rethinkdb copied to clipboard

Testing support 'containsArray' keyword in where clause

Open mako87 opened this issue 8 years ago • 1 comments

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']
     }
}

mako87 avatar Mar 23 '16 11:03 mako87

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

jmdobry avatar Sep 20 '16 14:09 jmdobry