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.

Use instance variable for modelName in BaseModel

See original GitHub issue

When 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:closed
  • Created 4 years ago
  • Reactions:3
  • Comments:14 (12 by maintainers)

github_iconTop GitHub Comments

2reactions
morphaticcommented, Sep 19, 2019

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.

2reactions
RubyRubenstahlcommented, Sep 3, 2019

White I try to declare the property as static, e.g.

class User extends BaseModel {
    static modelName = "user";
    constructor(data, options) {
        super(data, options)

    }

    static instanceDefaults() {
        return {
            username: '',
            email: '',
            password: ''
        }
    }
}

I receive the following error:

Module parse failed: Unexpected token (9:21)
File was processed with these loaders:
 * ./node_modules/eslint-loader/index.js
You may need an additional loader to handle the result of these loaders.
| // Extend the base class
| class User extends BaseModel {
>     static modelName = "user";
|     constructor(data, options) {
|         super(data, options)

 @ ./src/store/index.js 3:0-42 16:4-15
 @ ./src/main.js
 @ multi (webpack)-dev-server/client?http://192.168.123.107:8080/sockjs-node (webpack)/hot/dev-server.js ./src/main.js

To ensure that this error wasn’t specific to eslint, I disabled eslint an tried again, receiving essentially the same error:

Module parse failed: Unexpected token (11:21)
You may need an appropriate loader to handle this file type, currently no loaders are configured to process this file. See https://webpack.js.org/concepts#loaders| class User extends BaseModel {
|     // eslint-disable-next-line
>     static modelName = "user";
|     constructor(data, options) {
|         super(data, options)

I admit, I don’t use classes in JS all that often, so it may be just that I’m missing something.

Read more comments on GitHub >

github_iconTop 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 >

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