1

我正在尝试使用 Sails.js 和 ORM 框架 Waterline 对人网络进行建模。

我有一个 Person 模型,它通过 Relation 对象有很多人。我需要一种方法来包含关系连接模型中的分类属性。我希望能够使用 waterline 提供的populate()方法来获取与特定人员关联的人员列表。

一个人的建模如下:

/**
* Person.js
*/

module.exports = {
  attributes: {
    first_name: {
      type: 'string',
      required: true
    },
    middle_name: {
      type: 'string',
      required: false
    },
    last_name: {
      type: 'string',
      required: true
    },
    date_of_birth: {
      type: 'date',
      required: false
    },
    relations: {
      collection: 'person',
      via: 'related_from',
      through: 'relation'
    },
  }
};

一个关系模型如下:

/**
* Relation.js
*/

module.exports = {
  attributes: {

    classification: {
      type: 'string',
      required: true
    },

    related_to: {
      model: 'person'
    },
    related_from: {
      model: 'person'
    },
  }
};

提前致谢

4

0 回答 0