Repository navigation
Closed
Labels
Description
Issue Description
What are you doing?
I want to make sure for some Models that regardless of the selected attributes a certain attribute is always included. Up to version 6.3.5 this code worked:
Foo.init(
{
// ...
},
{
// ...
hooks: {
beforeFind(options: FindOptions<SequenceStepAttributes>): void {
if (options.attributes) {
if (Array.isArray(options.attributes)) {
options.attributes.push('type');
} else {
if (options.attributes.exclude) {
let index = options.attributes.exclude.indexOf('type');
while (index >= 0) {
options.attributes.exclude.splice(index, 1);
index = options.attributes.exclude.indexOf('type');
}
}
}
}
}
}
}
);What do you expect to happen?
The attribute type should always be queried.
What is actually happening?
The code does not compile, because 287607a changed all types within FindAttributeOptions into readonly.
Additional context
Is there some other way to achieve my goal?
Environment
- Sequelize version: 6.4.0
- Node.js version: v14.15.3
- Operating System: osx
- TypeScript version: 4.1.3
Issue Template Checklist
How does this problem relate to dialects?
- I think this problem happens regardless of the dialect.
- I think this problem happens only for the following dialect(s):
- I don't know, I was using PUT-YOUR-DIALECT-HERE, with connector library version XXX and database version XXX
Would you be willing to resolve this issue by submitting a Pull Request?
- Yes, I have the time and I know how to start.
- Yes, I have the time but I don't know how to start, I would need guidance.
- No, I don't have the time, although I believe I could do it if I had the time...
- No, I don't have the time and I wouldn't even know how to start.
Activity
papb commentedon Jan 19, 2021
Hello! Thank you very much for this very well written issue.
This was a mistake on my part. Indeed, parameters passed to hooks can be updated and it should work. This is a little unusual in JavaScript as a whole, but is indeed documented for Sequelize in this case. I will fix this and release a new version in the near future.
For now, please use
v6.3.5. Thanks!test(types): add failing test for #12959
fabrykowski commentedon Jan 26, 2021
Thank you for the quick fix!
papb commentedon Jan 26, 2021
@fabrykowski You're welcome, although I haven't made a new release yet 😅 will do soon!
github-actions commentedon Jan 27, 2021
🎉 This issue has been resolved in version 6.5.0 🎉
The release is available on:
Your semantic-release bot 📦🚀
meta: update expect-type to v1
meta: update expect-type to v1
meta: update expect-type to v1
meta: update expect-type to v1