-
-
Notifications
You must be signed in to change notification settings - Fork 4.3k
Closed
Labels
good first issueFor issues. An issue that is a good choice for first-time contributors.For issues. An issue that is a good choice for first-time contributors.type: bugDEPRECATED: replace with the "bug" issue typeDEPRECATED: replace with the "bug" issue type
Description
What you are doing?
// simple model with scopes that take parameters
var Location = sequelize.define('Location', {
state: types.STRING,
city: types.STRING
}, {
scopes: {
state: function(state) {
return {where: {state: state}};
},
city: function(city) {
return {where: {city: city}};
}
}
});
// create a scopes array to be reused
var scopes = [
{method: ['city', 'Springfield']},
{method: ['state', 'OH']}
];
// do some queries
Location.scope(scopes).count().then(console.log);
Location.scope(scopes).findAll().then(console.log);
What do you expect to happen?
I expect the arguments in the scopes to be passed into the queries for both queries.
What is actually happening?
Only the first query is using the arguments because the internal method
arrays on the scopes
array are being modified here when using .splice
.
Locally, I changed that to .slice
so the array isn't mutated and it fixed my use case. I did a little digging in the issues, but not enough to determine if this has come up before. If this is a bug, I can try to submit a PR when I get a chance to make the changes and provide unit tests.
Metadata
Metadata
Assignees
Labels
good first issueFor issues. An issue that is a good choice for first-time contributors.For issues. An issue that is a good choice for first-time contributors.type: bugDEPRECATED: replace with the "bug" issue typeDEPRECATED: replace with the "bug" issue type