问题
I want to perform a WHERE - IN
query/operation but normal where gives error.
I want this
select * from `calendar_event_rsvp` where `event_id` in ('1', '2', '3')
But below code leads to
select * from `calendar_event_rsvp` where `event_id in` = '1', '2', '3'
Code
CalendarEventRSVP.forge()
.where({
"event_id": event_ids
})
How do i do this in bookshelf.js
回答1:
Try to add the operator:
CalendarEventRSVP.forge()
.where('event_id', 'in', event_ids)
Or use knex's whereIn
:
CalendarEventRSVP.forge()
.query({whereIn: {event_id: event_ids}})
回答2:
try query() function on your model.
CalendarEventRSVP.query(function(qb){
qb.where('event_id' , 'in' , [1,2,3,4]) ;
})
.fetchAll()
.then();
来源:https://stackoverflow.com/questions/36131004/perform-a-where-in-query-in-bookshelf-js