Disable automatic population of models in sails v1.0

Viewed 586

I am using Sailsjs v1.0.0-36. I want to disable model population.

So when I send GET request to http://my-app/pets:

[
  {
    id: 1,
    breed: 'Wolves',
    type: 'Direwolf',
    name: 'Ghost',
    owner: 1, //user id
  }, 
  {
    id: 2,
    breed: 'Wolves',
    type: 'Direwolf',
    name: 'Summer',
    owner: 1, //user id
  },
]

and when I send GET request to http://my-app/users:

[
  {
     id: 1
     firstName: 'John',
     lastName: 'Snow',
     pets: [ //array of pets id
       1,
       2,
     ]
  }
]

Where User model defined as

// myApp/api/models/User.js
// A user may have many pets
module.exports = {
  attributes: {
    firstName: {
      type: 'string'
    },
    lastName: {
      type: 'string'
    },

    // Add a reference to Pets
    pets: {
      collection: 'pet',
      via: 'owner'
    }
  }
};

And Pet model defined as

// myApp/api/models/Pet.js
// A pet may only belong to a single user
module.exports = {
  attributes: {
    breed: {
      type: 'string'
    },
    type: {
      type: 'string'
    },
    name: {
      type: 'string'
    },

    // Add a reference to User
    owner: {
      model: 'user'
    }
  }
};

In Sails v0.12.0 you can do that in /config/blueprints.js by setting

populate = false

But this is deprecated in Sails v1.0, following this from the docs we can achieve that by overriding parseBlueprintOptions, and this is the default implementation of the function.

How can I override this to achieve the required results?

2 Answers
Related