I want to create a dynamic search using sequelize in multiple tables and all columns of this tables.
I want all results that include one or more columns of any table with the text inserted in search box.
I try something like that:
return await Models.table1.findAll({
subQuery: false,
attributes: [...
['description', 'name'],
'isActive'
],
include: [{
model: Models.table2,
as: 'data',
required: true,
attributes: [...
['description', 'name'],
'isActive'
],
where: {
isActive: 1,
description:{
$like: '%' + text + '%'
}
},
include: [{
model: Models.table3,
as: 'data',
required: true,
attributes: [
[...],
['description', 'name'],
'isActive'
],
where: {
isActive: 1,
description:{
$like: '%' + text + '%'
}
},
include: [{
model: Models.table4,
as: 'data',
required: true,
attributes: [
...
'comments',
'isActive'
],
where: {
isActive: 1
}
}]
}]
}],
where: {
isActive: 1
}
})
But I get the results just if all columns 'description' match the text. Can I start the query with the table4? Down to up, and return if anyone column match the text?