sails.jswaterline

Is there a way to add limit in global config model.js ? to limit find results across models in sails.js waterline


Is there a way to add a limit in global config model.js ? to limit model.find() results across models in sails.js waterline. As I searched the sails docs, dont find any direct config to use. https://sailsjs.com/documentation/reference/configuration/sails-config-models.

Are there are any hacks or workaround, where I configure it one place and all models find queries get the limit?


Solution

  • No, there isn't an easy way to change .find()'s behavior. However, you could very easily build a custom helper function, which you can then access through sails.helpers.mySpecialHelper().

    So, in this case, you'd pass in the model you want to .find(), and your criteria to the helper function, and said helper would return back the results the way you want them found.

    Then, inside of your helper, just do something like:

    PassedInModel.find(passedInCriteria);