gpt4 book ai didi

node.js - nodejs sequelize 加载嵌套模型

转载 作者:行者123 更新时间:2023-12-03 22:23:45 24 4
gpt4 key购买 nike

我的错误,问题不完整,用粗体标记所有缺失的文本

我有以下型号:

  • 患者
  • 个人
  • 地址
  • 患者地址


  • PatientAddress.belongsTo(Patient);
  • Patient.belongsTo(Personal);
  • PatientAddress.belongsTo(Address);

  • 我正在尝试阅读耐心并想阅读地址,它看起来像:

    患者 => 患者地址 => 地址

    我还需要阅读带有患者的个人模型

    我可以使用 include 读取 PatientAddress、Personal 但无法读取 Address。我试过这些:
    return Patient.findAll({
    limit: limit,
    offset: offset,
    include: [{
    model: [Personal, PatientAddress],
    include: [{
    Address
    }]
    }]
    });

    return Patient.findAll({
    limit: limit,
    offset: offset,
    include: [{
    model: [Personal, PatientAddress],
    include: [{
    PatientAddress.Address
    }]
    }]
    });

    或者
    return Patient.findAll({
    limit: limit,
    offset: offset,
    include: [Personal, PatientAddress, PatientAddress.Address]
    });

    要改变什么?

    最佳答案

    PersonalPatient 直接相关,但 Address 属于 PatientAddress 。因此,您必须将 Address -include 放在 PatientAddress 的包含中,而 Personal 保持第一级包含。

    return Patient.findAll({
    limit: limit,
    offset: offset,
    include: [
    {
    model: PatientAddress,
    include: [Address]
    },
    {
    model: Personal
    }
    ]
    });

    关于node.js - nodejs sequelize 加载嵌套模型,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/47123706/

    24 4 0
    Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
    广告合作:1813099741@qq.com 6ren.com