GithubHelp home page GithubHelp logo

clayrisser / nested-pop Goto Github PK

View Code? Open in Web Editor NEW
2.0 2.0 5.0 10 KB

Promise based nested populate for Waterline and SailsJS

Home Page: http://jam.jamrizzi.com

License: MIT License

JavaScript 100.00%

nested-pop's Introduction

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

nested-pop's People

Contributors

clayrisser avatar jamrizzi avatar

Stargazers

 avatar  avatar

Watchers

 avatar  avatar

nested-pop's Issues

Subcriteria in nested-pop

Dependency Version

    "@sailshq/connect-redis": "^3.2.1",
    "@sailshq/lodash": "^3.10.3",
    "@sailshq/socket.io-redis": "^5.2.0",
    "nested-pop": "^0.1.4",
    "sails": "^1.2.4",
    "sails-hook-apianalytics": "^2.0.3",
    "sails-hook-organics": "^2.0.0",
    "sails-hook-orm": "^2.1.1",
    "sails-hook-sockets": "^2.0.0",
    "sails-mysql": "^1.0.1"

Behavior

Using subcriteria inside nested-pop

Example

this is the example from original populate SailsJS

await User.find({name:'Finn'}).populate('dad', { name: 'John' })

or

await User.find().populate('friends', {
    where: {
        gender: 'female',
        name: { contains: 'putri' }
    },
    limit: 10,
    skip: 5,
    sort: 'name DESC'
})

Populate in nested-pop

Hey, i create a function to nested-pop my object. Is there any option to using another nested-pop in my nested-pop object?

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.