TiBianMod / vuex-orm-decorators

Decorator Syntax for Vuex ORM for better type safety.
MIT License
29 stars 11 forks source link

TypeError: this.types is not a function #3

Closed breynolds closed 4 years ago

breynolds commented 4 years ago

When I try to insert into the DB, I get the error TypeError: this.types is not a function

Entity looks like this

import { Model } from "@vuex-orm/core";
import { NumberField, OrmModel, StringField } from "vuex-orm-decorators";

@OrmModel("races")
export default class Race extends Model {
  @NumberField()
  public ID!: number;

  @StringField()
  public Name!: string;
}

store looks like this:

import Vue from "vue";
import Vuex from "vuex";
import { ORMDatabase } from "vuex-orm-decorators";

Vue.use(Vuex);

export default new Vuex.Store({
  .
  .
  .
  plugins: [ORMDatabase.install()]
});

Also, maybe this is a clue.... in Vuex-Orm, this.setters is returning a value, but this.setters('all') is returning undefined.

/**
 * Get all records.
 */
Model.all = function () {
   return this.getters('all')();
};

From seeing the undefined basic fields and functions, it seems like the vuex-orm database isn't getting set up correctly. Any ideas?

I also posted this on StackOverflow to see if other people have ideas. https://stackoverflow.com/questions/59020879/typeerror-this-types-is-not-a-function-when-using-vuex-orm-decorators

Scotley commented 4 years ago

Hi,

I'm not to sure from first glance, it all looks like it should be working fine. I will have a dig around tomorrow and see what I can work out for you. Potentially it is something that has changed in a newer version of vuex-orm.

I will get back to you.

breynolds commented 4 years ago

Ok, thanks for the info. If you need to, we can do a screen share.

On Mon, Nov 25, 2019 at 6:01 AM Scotley notifications@github.com wrote:

Hi,

I'm not to sure from first glance, it all looks like it should be working fine. I will have a dig around tomorrow and see what I can work out for you. Potentially it is something that has changed in a newer version of vuex-orm.

I will get back to you.

— You are receiving this because you authored the thread. Reply to this email directly, view it on GitHub https://github.com/Scotley/vuex-orm-decorators/issues/3?email_source=notifications&email_token=AALNPMOOX6KYZ26HSV55QW3QVOV7PA5CNFSM4JRG4FEKYY3PNVWWK3TUL52HS4DFVREXG43VMVBW63LNMVXHJKTDN5WW2ZLOORPWSZGOEFB75RI#issuecomment-558104261, or unsubscribe https://github.com/notifications/unsubscribe-auth/AALNPMJCNK3R65VJFAAGWXTQVOV7PANCNFSM4JRG4FEA .

Scotley commented 4 years ago

Can you share a some complete code which reproduces this issue please?

I need a bit more info on your issue. because I am struggling to reproduce it.

Edit: Reproduced your bug finally. I will continue to investigate but it manifests differently in different vuex-orm versions.

Scotley commented 4 years ago

Can you please confirm something for me.

If you try this:

store.dispatch('entities/races/insert', { data: { ID: 10, Name: 'Test' } })
console.log(Race.find(10));

Then you get the result that you expect and the race object is logged in the console.

but if you try:

Race.insert({ ID: 10, Name: 'Test' });

then you get the error.

(If this is your error, I don't have a fix or an explanation as it seems to be an issue with vuex-orm itself).

Not sure why, and unfortunately I am no longer actively using it as I developed my own style orm store as I didn't need the complexity of vuex-orm, but needed more flexibility. That is now my main focus :/

Still, if I have missed the mark entirely, drop a complete example of your bug and I will look further into it.

breynolds commented 4 years ago

I just tried directly calling the dispatch, and got the same thing.

Don't worry about it. If you're not really going to actively use this code, I'll work out something else. Thanks for looking into it for me.

Scotley commented 4 years ago

No dramas mate, I will pass this on to @Kiaking anyway and he might be able to confirm whether there is an issue in the base library or not.

kiaking commented 4 years ago

Oh well that's because the argument is wrong. It should be;

Race.insert({
  data: { ID: 10, Name: 'Test' } // <- You need `data` key.
});
Scotley commented 4 years ago

Aha, legend @kiaking. Thanks for that, I was missing the obvious for so long. @breynolds, is this solving your issue? Perhaps you were making the same mistake as me?

breynolds commented 4 years ago

Yeah, I had already tried that. Same issue.

On Nov 28, 2019, at 11:32 PM, Scotley notifications@github.com wrote:

Aha, legend @kiaking https://github.com/kiaking. Thanks for that, I was missing the obvious for so long. @breynolds https://github.com/breynolds, is this solving your issue? Perhaps you were making the same mistake as me?

— You are receiving this because you were mentioned. Reply to this email directly, view it on GitHub https://github.com/Scotley/vuex-orm-decorators/issues/3?email_source=notifications&email_token=AALNPMO7TQ3FJUA4C3SUEWTQWCEMXA5CNFSM4JRG4FEKYY3PNVWWK3TUL52HS4DFVREXG43VMVBW63LNMVXHJKTDN5WW2ZLOORPWSZGOEFNY4RI#issuecomment-559648325, or unsubscribe https://github.com/notifications/unsubscribe-auth/AALNPMPBSIGFH66CDKGXRADQWCEMXANCNFSM4JRG4FEA.