Model inheritance chain causes associations to throw an error
See original GitHub issueWhat 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:
- Created 6 years ago
- Comments:9
Top 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 >
Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free
Top Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
@jawadakram20 I didn’t fix the issue and I ended up not using Sequelize.
@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
:ModelNameGoesHere
is a model that is defined in a separate npm package. That is, it comes fromWhen I copy the code from the package into my application, the problem goes away.
Is there any solution to this?