Node.js 模型关联不在水线上工作

Node.js 模型关联不在水线上工作,node.js,mongodb,sails.js,waterline,hapijs,Node.js,Mongodb,Sails.js,Waterline,Hapijs,我正在使用该包将水线ORM集成到基于Hapi的NodeJS项目中 我无法使用简单的一对多关联(底层数据库是Mongo) 所有者模型如下所示: identity: 'companies', tableName: 'companies', connection: 'viveatDashboard', schema: true, attributes: { _id: { type: 'string', primaryKey: true,

我正在使用该包将水线ORM集成到基于Hapi的NodeJS项目中

我无法使用简单的一对多关联(底层数据库是Mongo)

所有者模型如下所示:

  identity: 'companies',
  tableName: 'companies',

  connection: 'viveatDashboard',
  schema: true,
  attributes: {
    _id: {
      type: 'string',
      primaryKey: true,
      required: true,
      unique: true
    },
    apps: {
      collection: 'apps',
      via: 'companyId'
    },
    ... // more attributes here
    migrate: 'safe',
    autoCreatedAt: true,
    autoUpdatedAt: true,
引用公司的模型如下所示:

  identity: 'apps',
  tableName: 'apps',

  connection: 'viveatDashboard',
  schema: true,

  _id: {
    type: 'string',
    primaryKey: true,
    required: true,
    unique: true
  },

  companyId: {
    type: 'string',
    required: true,
    model: 'companies'
  },
  ... // more attributes here
  migrate: 'safe',
  autoCreatedAt: true,
  autoUpdatedAt: true,
当路由处理程序的代码运行时:

...
Companies.find().populate('apps').exec(function(err, apps) {
  return reply(apps);
});

获取的记录的apps属性是一个空数组(我确保确实存在引用现有公司的应用)。

显然,问题是如果
\u id
属性用作
primaryKey
,然后,它必须在模型架构中作为
id
引用,而不是作为
\u id
引用

现在关联工作正常。

尝试运行
sails lift--silly
并触发处理程序。日志应该提供一些对调试有用的额外信息