perform a where in query in bookshelf.js

僤鯓⒐⒋嵵緔 提交于 2019-12-10 06:13:27

问题


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

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!