Reputation: 1823
I do not understand how to perform the following query:
explanation:
I am trying to filter my outcomes based on a value which is within a Table, which is associated to a Table which is associated to the Model I'm trying to filter.
FilteredModel <--(hasMany)-- MiddleModel --(hasone)--> LastModel
FilteredModel.findAll({
where: {
...conditions,
['$MiddleModel.LastModel.property$']: VARIABLE
}
});
I have included the necessary models and I receive the value of the property I sought in the outcome.
I just do not understand how to add it to the where
considerations.
I tried the provided example in many forms as suggested in other SOF answers, receiving a: SequelizeDatabaseError: Unknown column 'FilteredModel->MiddleModel->LastModel.property' in 'where clause'
error.
May I have some guidance here?
Upvotes: 0
Views: 223
Reputation: 866
Hi try below code -
Db.orders.findAll({
where: { ORDER_CONDITION },
attributes: [ORDER ATTRIBUTES],
include: [
{
where: { INNER1_WHERE },
required: true,
model: INNER1,
include: [
{
where: { INNER2_WHERE },
required: true,
model: INNER2
},
]
},
]
});
required: true param in include plays an important role of only including those orders whose includes are present
Also in your code, I didn't see the include option but you are using where condition on an include attributes ['$MiddleModel.LastModel.property$']: VARIABLE
Upvotes: 1