如何在 sequelize 的 sub-sub 子模型中添加条件,这会影响 findAndCountAll 中的父模型?

问题描述

在 sequelize 中,我想在 sub-sub 子模型的 findAndCountAll 调用中添加一个条件。如果条件为假,它应该影响父模型, findAndCountAll 应该返回数组长度 0。目前,只有子子模型的数组长度为 0,其余父模型正在返回。

我在共享的代码中添加了更多详细信息。 我的代码是这样的:

    const { limit,offset } = dbHelpers.GetPagination(
        req.query.limit,req.query.offset
    );
    
    const results = await models.ModelA.findAndCountAll({
        where: condition,distinct: true,limit,offset,order: [["id","DESC"]],include: [
            {
                model: models.ModelB,as: "ModelB",include: [
                    {
                        model: models.ModelC,separate: true,},{
                        model: models.ModelD,include: [
                            {
                                model: models.ModelE,{
                                        model: models.ModelF,where: "I want to add my condition here which should impact the whole query if not found just like the condition I have added in ModelG",],{
                model: models.ModelG,where: "I have added a condition here and if nothing is found,my parent query returns nothing which is exactly what I want.",include: [
                    {
                        model: models.ModelH,as: "ModelH",});

解决方法

暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!

如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。

小编邮箱:dio#foxmail.com (将#修改为@)