SailsJs through association - 模型错误中没有相应的属性

SailsJs through association - no corresponding attribute in the model error

背景 - 我有一个 Company 记录列表,我正在匹配合并到 MergedCompany 记录中。

我正在尝试创建直通表/模型 CompanyMergedCompany

// models/Company.js

  attributes: {

  mergedcompany: {
    collection: 'mergedcompany',
    via: 'companies',
    through: 'companymergedcompany'
  }
}
// models/MergedCompany.js

  attributes: {

    companies: {
      collection: 'company',
      via: 'mergedcompany',
      through: 'companymergedcompany`'
    },
}
// models/CompanyMergedCompany.js

  attributes: {

   mergedcompany: {
      model: 'mergedcompany'
    },

    company: {
      model: 'company'
    },

}

启动应用程序时出现错误:

error: Failed to lift app: userError: A `through` property was set on the attribute `mergedcompany` on the `company` model but no corresponding attribute in the `mergedcompany` model could be found pointing with the same `through` value (`companymergedcompany`).

如何通过关联正确创建这个?

在您的公司模型中试试这个

 attributes: {

  mergedcompany: {
    collection: 'mergedcompany',
    via: 'company',
    through: 'companymergedcompany'
  }
}

您必须在 Company 和 MergedCompany 的 via 选项中提供“Thorugh Model”(CompanyMergedCompany) 中的密钥