Skip to content

Casts do not appear to work when using pinia-orm-axios plugin #2003

Description

@dschreij

Environment

------------------------------
- Operating System: Linux
- Node Version:     v22.14.0
- Nuxt Version:     3.16.2
- CLI Version:      3.24.1
- Nitro Version:    2.11.8
- Package Manager:  pnpm@10.10.0
- Builder:          -
- User Config:      ssr, compatibilityDate, app, future, devtools, imports, watch, runtimeConfig, plugins, modules, auth, lodash, i18n, vuetify, piniaOrm, pinia, css, eslint
- Runtime Modules:  @nuxt/eslint@1.3.0, @nuxt/image@1.10.0, @nuxt/scripts@0.11.5, @nuxt/test-utils@3.17.2, @nuxt/test-utils/module@3.17.2, @nuxtjs/i18n@9.4.0, @pinia/nuxt@0.10.1, @pinia-orm/nuxt@1.10.2, @sidebase/nuxt-auth@0.10.1, @vueuse/nuxt@13.0.0, @zadigetvoltaire/nuxt-gtm@0.0.13, nuxt-lodash@2.5.3, vuetify-nuxt-module@0.18.5, @formkit/auto-animate/nuxt@0.8.2, nuxt-authorization@0.3.3
- Build Modules:    -
------------------------------

Reproduction

Given the following Model and repository:

export class Note extends Model {
  static override entity = 'notes'
  static override primaryKey = 'id'

  @Str(null) declare id: string
  @Cast(() => NumberCast) @Num(null) declare organization_id: number
}

export class NoteRepository extends Repository<Note> {
  override use = Note

  fetchAll(entity: NoteParentEntity, entityId: number, config?: RequestConfig, role = UserRole.CLIENT) {
    return useAxiosRepo(Note).api().get(`${endpoints[role].note}/${entity}/${entityId}`, config)
  }
}

the endpoint returns the following data (irrelevant fields omitted):

[
        {
            "id": "d08vmht2qt7tm9nhrnq0",
            "organization_id": "10191",
        },
]

Describe the bug

Once data is received, the browser console prints the following error:

Field notes:organization_id -  10191 is not a number

even though the cast should take care of casting the retrieved string to a number, if I understand it correctly

Additional context

No response

Logs

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions