question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Model inheritance chain causes associations to throw an error

See original GitHub issue

What you are doing?

class MyBaseModel extends Model {
  ...
}

class MyActualModel extends MyBaseModel {
  ...
}

class MyOtherModel extends MyBaseModel {
  ...
}

MyActualModel.hasMany(MyOtherModel)

What do you expect to happen?

I expected this to not throw an error.

What is actually happening?

MyActualModel.hasMany called with something that's not a subclass of Sequelize.Model

It looks like the instanceof check on line 12 of mixin.js is a little too strict and should just be !(target instanceof this.sequelize.Model). Right now it’s checking target.prototype instead of just target.

Dialect: any Database version: N/A Sequelize version: 4.8.0

Issue Analytics

  • State:closed
  • Created 6 years ago
  • Comments:9

github_iconTop GitHub Comments

2reactions
jimsimoncommented, Mar 25, 2018

@jawadakram20 I didn’t fix the issue and I ended up not using Sequelize.

0reactions
nbkhopecommented, May 19, 2021

@peabnuts123 I have a project that defines some models as a separate npm package. When I import those models in my project and start my application, I get an error when it calls .associate:

Error: ModelNameGoesHere.hasMany called with something that's not a subclass of Sequelize.Model

ModelNameGoesHere is a model that is defined in a separate npm package. That is, it comes from

import ModelNameGoesHere from 'some-separate-npm-package'

When I copy the code from the package into my application, the problem goes away.

Is there any solution to this?

Read more comments on GitHub >

github_iconTop Results From Across the Web

Inheritance and the prototype chain - JavaScript | MDN
However, because this reassigns the prototype property and removes the constructor property, it can be more error-prone, while performance gains ...
Read more >
Considering When To Throw Errors, Why To Chain Them ...
Ben Nadel writes up the results of his research on error handling in web application development - when to throw errors, why to...
Read more >
Prototypal inheritance
Here we have the following inheritance chain: rabbit inherits from animal , that inherits from Object. prototype (because animal is a literal ...
Read more >
Exceptions in Detail (Especially Inheritance)
The Throwable Inheritance Hierarchy, Here is a diagram of the most prominent classes in the inheritance hierarchy that Java uses for throwing exceptions....
Read more >
Generalization, Specialization, and Inheritance
If it turns out that certain attributes, associations, or methods only apply to some of the objects of the class, a subclass can...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found