CodeDredd / pinia-orm

The Pinia plugin to enable Object-Relational Mapping access to the Pinia Store.
https://pinia-orm.codedredd.de/
MIT License
449 stars 38 forks source link

TypeError: attr.setKey is not a function #426

Closed MHassanSaqib closed 1 year ago

MHassanSaqib commented 2 years ago

Environment

Reproduction

I just change the primaryKey name. And start getting this error. Now, I changed the name of Model from Pagination to Paginate, everything is working fine. There must be some caching strategy that is causing this bug.

Describe the bug

TypeError: attr.setKey is not a function
    at Pagination.$fillField (index.mjs:1609:98)
    at Pagination.$fill (index.mjs:1586:27)
    at new Model (index.mjs:1383:18)
    at new Pagination (Pagination.js:4:16)
    at Pagination.$newInstance (index.mjs:1542:12)
    at Query.checkAndGetSTI (index.mjs:749:70)
    at Query.hydrate (index.mjs:738:93)
    at Query.saveElements (index.mjs:643:120)
    at Query.save (index.mjs:632:13)
    at Repository.save (index.mjs:966:25)

Getting the above error. The model is as shown below:

import { Model } from "pinia-orm";
import { UidCast } from "pinia-orm/dist/uuid/v1";

export default class Pagination extends Model {
  static entity = "paginations";
  static primaryKey = "repoName";
  static fields() {
    return {
      id: this.attr(""),
      repoName: this.attr(""),
      indexOrder: this.attr(""),
      nextPage: this.attr(""),
    };
  }
  static casts() {
    return {
      id: UidCast,
    };
  }
}

At first, it was working fine and then it start throwing this error. Not sure what is causing the error.

Additional context

If there is some caching strategy, we can remove the cache on server restart or on some sort of watchdog event.

Logs

No response

CodeDredd commented 2 years ago

Would you provide a reproduction? 🙏

CodeDredd commented 1 year ago

@MHassanSaqib I am closing this now. Feel free to reopen if this bug still happens and is reproducable. Thank you.