Left excluding join in sequelize
You need to eager load EventFeedback
when querying UserEvent
and add proper where
clause. You also need to define that EventFeedback
is not required in the result so the query will generate LEFT JOIN
instead INNER JOIN
UserEvent.all({
include: [
model: EventFeedback,
required: false, // do not generate INNER JOIN
attributes: [] // do not return any columns of the EventFeedback table
],
where: sequelize.where(
sequelize.col('EventFeedback.userEventID'),
'IS',
null
)
}).then(userEvents => {
// user events...
});
In the code above the sequelize
is an instance of Sequelize with model defined in it. You can also refer to the documentation of sequelize.where()
and sequelize.col()
methods.