Skip to content

Readonly arrays – why? #12959

Closed
Closed

Description

@fabrykowski

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

  1. papb commented on Jan 19, 2021

    @papb
    Member

    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!

  2. fabrykowski commented on Jan 26, 2021

    @fabrykowski
    Author

    Thank you for the quick fix!

  3. papb commented on Jan 26, 2021

    @papb
    Member

    @fabrykowski You're welcome, although I haven't made a new release yet 😅 will do soon!

  4. github-actions commented on Jan 27, 2021

    @github-actions
    Contributor

    🎉 This issue has been resolved in version 6.5.0 🎉

    The release is available on:

    Your semantic-release bot 📦🚀

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions