syncano-node icon indicating copy to clipboard operation
syncano-node copied to clipboard

Method: whereNotBetween

Open Idered opened this issue 8 years ago • 3 comments

// Get posts with number of votes not between 50 and 100
data.posts
  .whereNotBetween('votes', 50, 100)
  .list()

Idered avatar Nov 09 '17 10:11 Idered

@23doors any idea how to build query for that?

For whereBetween this works:

whereBetween(column, min, max) {
  return this.where([
    [column, 'gte', min],
    [column, 'lte', max]
  ])
}

For whereNotBetween this doesn't work:

whereNotBetween(column, min, max) {
  return this.where([
    [column, 'lt', min],
    [column, 'gt', max]
  ])
}

I can make an additional query to get all records between min and max and exclude those by id.

Idered avatar Nov 09 '17 17:11 Idered

@Idered We do not have OR in core (and we probably won't add it any time soon) so I think the only way to do it is to make two queries - where column lt min + where column gt max and join the results.

23doors avatar Nov 09 '17 17:11 23doors

@23doors okey, thanks!

Idered avatar Nov 09 '17 17:11 Idered