Skip to content

A more descriptive error when a model is being used without being initialized. #11837

Closed

Description

@bobspace

Issue Description

Is your feature request related to a problem? Please describe.

Associating models via hasOne, belongsTo, etc. fails if the dependent model has not been initialized. This can happen if models are initialized in the wrong order, or a set has not been entirely initialized when an association method is called (as was the case in #11691).

Describe the solution you'd like

Perhaps a quick check to a flag set when a model is initialized, and it throwing a descriptive error when method is called that requires a model to be initialized first.

Why should this be in Sequelize

Noticing that various properties are undefined does not point the way to the init function, unless you're familiar with the lifecycle of a Sequelize model. A more descriptive error would save time and ultimately improve stability.

Describe alternatives/workarounds you've considered

The alternative is suffering and wasting @papb's time until you happen to notice that your setup code is running out of order.

Additional context

¯_(ツ)_/¯

Issue Template Checklist

Is this issue dialect-specific?

  • No. This issue is relevant to Sequelize as a whole.
  • Yes. This issue only applies to the following dialect(s): XXX, YYY, ZZZ

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. added
    status: understood
    type: other
    on Jan 19, 2020
  2. papb commented on Jan 19, 2020

    @papb
    Member

    The alternative is suffering and wasting @papb's time until you happen to notice that your setup code is running out of order.

    😆

  3. github-actions commented on Nov 3, 2021

    @github-actions
    Contributor

    This issue has been automatically marked as stale because it has been open for 7 days without activity. It will be closed if no further activity occurs. If this is still an issue, just leave a comment or remove the "stale" label. 🙂

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

    status: understoodtype: other

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions