Skip to content

clayrisser/nested-pop

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

15 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

nested-pop

Promise based nested populate for Waterline and SailsJS

Installation

$ npm install --save nested-pop

Usage

var nestedPop = require('nested-pop');

User.find()
.populate('dog')
.then(function(users) {

    return nestedPop(users, {
        dog: [
            'breed'
        ]
    }).then(function(users) {
        return users;
    }).catch(function(err) {
        throw err;
    });
    
}).catch(function(err) {
    throw err;
);

If the property is named differently than the model, you may need to use it the following way.

var nestedPop = require('nested-pop');

User.find()
.populate('canine')
.then(function(users) {

    return nestedPop(users, {
        canine: {
            as: 'dog',
            populate: [
                'breed'
            ]
        } 
    }).then(function(users) {
        return users;
    }).catch(function(err) {
        throw err;
    });
    
}).catch(function(err) {
    throw err;
);

If the property is plural, but the model is in the singular form, it usually automatically detects it. This only works when the property's plural form only adds a single 's' to the end of the model name.

var nestedPop = require('nested-pop');

User.find()
.populate('dogs')
.then(function(users) {

    return nestedPop(users, {
        dogs: [
            'breed'
        ]
    }).then(function(users) {
        return users;
    }).catch(function(err) {
        throw err;
    });
    
}).catch(function(err) {
    throw err;
);

License

MIT © Jam Risser

About

Promise based nested populate for Waterline and SailsJS

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Contributors 3

  •  
  •  
  •