0
前提是我在sequelize
列從名單包括sequelize
return models.VehicleModel
.findAll({
include: [
{
attributes: ['id'],
model: models.Unit
},
{
model: models.myPattern,
where: {
VehicleModelId: { $in: data.VehicleModelIds }
},
include: [
{
model: models.Calendar,
include: [
{
model: models.Restrictions,
include: [
{
model: models.RestrictionType
}],
where: {
//THIS IS THE LINE I NEED TO CHANGE SOMEHOW
UnitId: { $in: [models.Unit.id] }
},
required: false
}
]
}
]
}
],
where: {
id: { $in: data.VehicleModelIds }
}
})
下面的語句這給了我NULL
查詢像這樣:
[myPattern.Calendar.Restrictions].UnitId IN (NULL) AND ....
我希望能夠得到以下相反:
[myPattern.Calendar.Restrictions].UnitId IN (Units.id) AND ....
這是因爲他們不是必須在那裏,但應該o當然可以鏈接到與車型對應的適當單位。
該myPattern
鏈接到Calendar
誰又依次鏈接到Restrictions
,所以到Units
。 這一切全部使用id
列。
任何幫助,將不勝感激!