Sails and Waterline: Include attributes from join table in through association

337 Views Asked by At

I am trying to model a network of people using Sails.js and the ORM framework, Waterline.

I have a Person model which has many People through a Relation object. I need a way to include the classification attribute from the Relation join model. I would like to be able to use the populate() method provided by waterline to get a list of people associated to a particular person.

A Person is modeled as follows:

/**
* 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'
    },
  }
};

A relation model is as follows:

/**
* Relation.js
*/

module.exports = {
  attributes: {

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

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

Thanks in advance

0

There are 0 best solutions below