[英]how to make a conditional in where. SEQUELIZE mysql
應該獲取在 coursesOffered 數組中找到值“搜索”的所有教師。
表老師
name lastName dob coursesOffered
胡安佩雷斯 2022/10/02 ['數學','科學']
馬科斯·史密斯 2022/10/02 [ '歷史', '文學' ]
查詢續集
const search = 'math';
const teachers = await Teacher.findAll({
where: should fetch all teachers where the value 'search' is found in the coursesOffered array.
})
你可以試試JSON_CONTAINS
function。
// When you are doing string search, make sure to wrap the search term with "".
const teachers = await Teacher.findAll({
where: Sequelize.fn('JSON_CONTAINS', Sequelize.col('coursesOffered'), `"${search}"`)
})
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.