Waterline ORM error: Error: Trying to access a collection string that is not defined

Waterline ORM error: Error: Trying to access a collection string that is not defined

我正在使用带有水线 ORM 的 sails 版本 0.12 来生成模型。我在尝试 运行 sudo sails lift 命令时收到此错误 Error: Trying to access a collection string that is not defined

module.exports = {

  attributes: {
    manufacturer_name: {
      type: 'string'
    },
    manufacturer_logo_url: {
      type: 'string'
    },
    manufacturer_archived_status: {
      type: 'boolean'
    },
    manufacturer_tabs: {
      model: 'manufacturer_tabs'
    },
    brands: {
      model: 'brands'
    }
  }
};

在您与模型的关联中,模型的名称必须与模型的确切名称相匹配,即文件名。通常您的模型(文件名)应该采用 JAVA 风格的 CamelCase(或 PascalCase)表示法。所以你的代码应该是这样的:

module.exports = {

  attributes: {
    manufacturer_name: {
      type: 'string'
    },
    manufacturer_logo_url: {
      type: 'string'
    },
    manufacturer_archived_status: {
      type: 'boolean'
    },
    manufacturer_tabs: {
      model: 'ManufacturerTabs'
    },
    brands: {
      model: 'Brands'
    }
  }
};

并且您的关联模型应位于名称为 ManufacturerTabs.js 和 Brands.js 的文件中。

我的建议:避免使用 C 和系统编程风格的符号,因为它在现代脚本语言中不再被广泛接受,python 除外。 javascript 代码使用驼峰式命名法。因此,请考虑将 manufacturer_name 替换为 manufacturerName,将 manufacturer_logo_url 替换为 manufacturerLogoUrl 等。虽然这是您的选择,但是嘿,遵循约定很好。