Sequelize with multiple arguments to multiple scopes not working

Viewed 233

I am trying to add multiple scopes along with defaultScope in query model.

var scopes = [
    'defaultScope',
    { method: ['nearByProperty', { lat, lng }] },
    { method: ['priceRangeFilter', { min_price, max_price }] }, 
];
propertyModel = propertyModel.scope(scopes)

It seems it works default and the last one but not all 3 of them. Also all 3 scopes workable if run separately but does not work together.

As per the docs it shows just a single argument passing example.

https://sequelize.org/master/manual/scopes.html#merging

Please help me out if I am doing something wrong.

1 Answers

Does your function take in an a single object argument or two arguments?

If two, try spreading the arguments and passing them in as so:

var scopes = [
    'defaultScope',
    { method: ['nearByProperty',  lat, lng ] },
    { method: ['priceRangeFilter', min_price, max_price ] }
];
Related