Sunday, 2 April 2017

SailsJS Perform sorting on populate data

Here is my current event model:

module.exports = {
    attributes: {
        name: {
            type: 'string',
            required: true,
            unique: true
        },
        client: {
            model: 'client',
            required: true
        },
        location: {
            model: 'location',
            required: true
        }
    }
};

The client Model:

module.exports = {
    attributes: {
        name: {
            type: 'string',
            required: true,
            unique: true
        },
        address: {
            type: 'string'
        },
        clientContact: {
            model: 'user',
            required: true
        }
    }
};

So how do I implement sorting based on the client name and also have the skip and limit property(for pagination) to work along with it.

I tried using the following query:

Event.find({id:["583eb530902db3d926345215","583eb6dd91b972ee26dd97b1"]},{select:["name","client"]}).populate("client",{sort:"name DESC"}).exec((err,resp)=>resp.map(r=>console.log(r.name,r.client)));

But this does not seem to do it.



via Panic

No comments:

Post a Comment