-
-
Notifications
You must be signed in to change notification settings - Fork 4.3k
Schrödingers defaultScope: defaultScope exists but at the same time does not #5277
Description
I have a model with no defaultScope defined explicitly. So when I do:
Token.scope('defaultScope').findAll()
I get an error:
Error: Invalid scope defaultScope called.
at W:\dev\node_modules\sequelize\lib\model.js:1214:13
When I try to add a defaultScope using Token.addScope('defaultScope', {}) (without setting the override: true flag) I get another error:
Error: The scope defaultScope already exists. Pass { override: true } as options to silence this error
at [object Object].Model.addScope (W:\temp\node_modules\sequelize\lib\model.js:1100:11)
So it looks like a defaultScope is not defined thus invalid but at the same time it seems to be defined internally because I get an error that it is already defined (which it is not really).
In my usecase I want to execute database operations based on REST requests. So:
GET /users/2
is mapped to:
Users.scope(req.query.scope || 'defaultScope').findById(req.params.id);
Since defaultScope is not explicitly defined, I get the error above. I think it would be nice (and probably wouldn't cause any problems) if an "empty" defaultScope is always defined (defaulting to {}). Or option 2: allow to set a defaultScope using the addScope() method without being forced to set the override flag.