【问题标题】:Sequelize select only rows with more than one recordSequelize 仅选择具有多条记录的行
【发布时间】:2017-05-18 23:29:47
【问题描述】:

我有这个问题:

Time_Sheet_Details.findAll({
      include: [
          {
              model: timesheetNotesSubcon,
              required: false,
              attributes:["note","file_name", "id", "working_hrs", "timestamp", "has_screenshot", "notes_category", "userid"],
          },
          {
              model: Timesheet,
              attributes:["id","leads_id","userid","subcontractors_id"],
              where:  clientWhere, // Client
              include:[
                  {
                      model: Lead_Info, attributes:["id","fname","lname","email","hiring_coordinator_id","status"],
                      where:  scWhere, // SC
                      include:[{
                          model: adminInfoSchema,
                          required: false,
                          attributes:["admin_id","admin_fname", "admin_lname", "admin_email", "signature_contact_nos", "signature_company"],
                      }]

                  },
                  {
                      model:Personal_Info,attributes:["userid","fname","lname","email"],
                  }
              ]
          }],
      where: {
          reference_date: filters.reference_date
      },
      order:[
          ["id","DESC"]
      ],
      offset:((page-1)*limit),
      limit : limit,
      subQuery:false

  }).then(function(foundObject){
      willFulfillDeferred.resolve(foundObject);
  });

我的设置是我有一个 Timesheet 有一个 TimesheetDetails 有很多 timesheetNotesSubcon 。我正在获取TimesheetDetails 一起将所有timesheetNotesSubcon 与它一起。

它工作正常,但是如果我只想获取 timesheetNotesSubcon 的那些 timesheetNotesSubcon 等于或多于 1 条记录,那么所有 TimesheetDetailstimesheetNotesSubcon 中的结果为零的所有 timesheetNotesSubcon 都不会被获取。

【问题讨论】:

    标签: mysql node.js sequelize.js


    【解决方案1】:

    你需要制作包含的模型required

    Time_Sheet_Details.findAll({
      include: [
          {
              model: timesheetNotesSubcon,
              required: true,
    ...
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2021-08-23
      • 2023-03-16
      • 1970-01-01
      • 1970-01-01
      • 2023-03-30
      • 2020-06-24
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多