在通过表上设置belongsToMany
时,我找不到找到所有包含的paranoid=true
模型的方法。请注意,我已经添加了相关条件以在查询的每个阶段返回软删除的模型,以表明它们都不起作用...(version 3.31.1
)
const User = sequelize.define('user', {})
const Conversation = sequelize.define('conversation', {})
const ConversationUser = sequelize.define('conversationUser', {}, {
paranoid: true,
})
User.belongsToMany(Conversation, { through: ConversationUser })
Conversation.belongsToMany(User, { through: ConversationUser })
现在假定已创建一个user
实例,我将尝试获取该用户的对话...
const options = {
include: [{
model: models.user,
as: 'members',
through: {
paranoid: false,
where: {
deleted_at: {
$or: [null, { $not: null }],
},
},
},
paranoid: false,
where: {
deleted_at: {
$or: [null, { $not: null }],
},
},
}],
paranoid: false,
where: {
deleted_at: {
$or: [null, { $not: null }],
},
},
};
const conversations = await user.getConversations(options);
conversations
将不包含任何软删除的模型,这些模型返回的结果与查询选项中未包含任何偏执条件相同。