How do I do a nested join in sails.js and waterlines?

In sails.js I have the following models:

Website

module.exports = {
  attributes: {
    name: {
        type: 'string',
        required: true
    },
    active: {
        type: 'boolean',
        defaultTo: false
    },
    pages: {
        collection: 'page',
        via 'site'
    }
  }
};

      

Page

module.exports = {
  attributes: {
    name: {
        type: 'string',
        required: true
    },
    site: {
        model: 'site',
        required: true
    },
    modules: {
        collection: 'module',
        via 'page'
    }
  }
};

      

Module

module.exports = {
  attributes: {
    module: {
        type: 'string',
        required: true
    },
    page: {
        model: 'page',
        required: true
    }
  }
};

      

When I call GET / Site / 1, I get this:

{
    "pages": [
        {
            "name": "First page",
            "site": 1,
            "createdAt": "2014-08-23T17:57:41.562Z",
            "updatedAt": "2014-08-23T17:57:41.562Z",
            "id": 1
        }
    ],
    "name": "First site",
    "createdAt": "2014-08-23T17:56:57.143Z",
    "updatedAt": "2014-08-23T17:56:57.143Z",
    "id": 1
}

      

I am using MongoDB and it would not be easy to model as a nested document. Unfortunately I don't think Waterline supports this hence the associations / unions.

I can see that it is successfully displaying every page associated with the site, how can I make it so that it also displays a list of modules associated with each page?

+3


source to share


1 answer


This thread might help. There is essentially no direct way to capture nested associations.



+3


source







All Articles