Use instance variable for modelName in BaseModel
See original GitHub issueWhen setting up the base model using javascript instead of typescript, the modeName needs to be added outside of the class, e.g:
// Extend the base class
class User extends BaseModel {
constructor(data, options) {
super(data, options)
}
static instanceDefaults() {
return {
username: '',
email: '',
password: ''
}
}
}
User.modelName = "user"
While it works, I think it could cause some confusion and lead to erroneous bug reports.
I propose that it, instead, be defined as an instance variable in the constructor:
// Extend the base class
class User extends BaseModel {
constructor(data, options) {
super(data, options)
this.modelName = "user"
}
static instanceDefaults() {
return {
username: '',
email: '',
password: ''
}
}
}
I’m not sure if this is feasible, given how & where it is used, but I think could reduce friction in supporting both TS and JS use cases.
Issue Analytics
- State:
- Created 4 years ago
- Reactions:3
- Comments:14 (12 by maintainers)
Top Results From Across the Web
pydantic BaseModel with instance variable - Stack Overflow
I'm using pydantic with fastapi. And ...
Read more >Models and Fields — peewee 3.15.4 documentation
Model configuration is kept namespaced in a special class called Meta . This convention is borrowed from Django. Meta configuration is passed on...
Read more >Model instance reference - Django documentation
Model instance reference¶. This document describes the details of the Model API. It builds on the material presented in the model and database...
Read more >Model Basics | Sequelize
In this tutorial you will learn what models are in Sequelize and how to use them.
Read more >Models - pydantic
Although validation is not the main purpose of pydantic, you can use this library for custom validation. Basic model usage¶. from pydantic import...
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 FreeTop 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
Top GitHub Comments
Ugh. Figured it out.
Rolled back to a commit from a month ago (when it still worked). Re-implemented all changes since then one by one. Upgraded all packages one-by-one, recompiling each time. Finally found the dependency that was causing the problem (
vue-cli-plugin-vuetify
). And it was only a patch upgrade (0.6.1 -> 0.6.3)!Hey, it only took a week!
Anyway, false alarm. No issues with
feathers-vuex
. Thanks to anyone to who spent time looking into or thinking about this.White I try to declare the property as static, e.g.
I receive the following error:
To ensure that this error wasn’t specific to eslint, I disabled eslint an tried again, receiving essentially the same error:
I admit, I don’t use classes in JS all that often, so it may be just that I’m missing something.