Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Error: [Pinia ORM] The record is missing the primary key. #1610

Open
martinszeltins opened this issue Sep 6, 2023 · 8 comments
Open

Error: [Pinia ORM] The record is missing the primary key. #1610

martinszeltins opened this issue Sep 6, 2023 · 8 comments
Labels
bug Something isn't working has workaround The issue contains a temporary solution to get around the problem nuxt 3

Comments

@martinszeltins
Copy link

Environment

- Operating System: Ubuntu 20.04 LTS (Linux)
- Node Version:     v18.12.1
- Nuxt Version:     3.7.1
- CLI Version:      3.7.3
- Nitro Version:    2.6.2
- Package Manager:  [email protected]
- Builder:          -
- User Config:      devtools, modules
- Runtime Modules:  @pinia/[email protected], @pinia-plugin-persistedstate/[email protected], @pinia-orm/[email protected]
- Build Modules:    -

Reproduction

https://github.com/martinszeltins/pinia-orm-new

Describe the bug

I am getting this error:

Uncaught Error: [Pinia ORM] The record is missing the primary key. If you want to persist record without the primary key, please define the primary key field with the `uid` attribute.
    at throwError (pinia-orm.js?v=65a69f6d:104:9)
    at assert (pinia-orm.js?v=65a69f6d:108:5)
    at User.$getIndexId (pinia-orm.js?v=65a69f6d:3054:5)
    at pinia-orm.js?v=65a69f6d:1567:21
    at Array.reduce (<anonymous>)
    at _Query.compile (pinia-orm.js?v=65a69f6d:1566:23)
    at _Query.insert (pinia-orm.js?v=65a69f6d:1426:32)
    at Repository.insert (pinia-orm.js?v=65a69f6d:1898:25)
    at addUser (app.vue:11:16)
    at callWithErrorHandling (vue.js?v=2c56b3b3:1565:18)

I have a very simple setup as you can tell from my reproduction repo. I just followed the docs.

  1. I created user.ts Model:
import { Model } from 'pinia-orm'
import { Str, Uid } from 'pinia-orm/dist/decorators'

export default class User extends Model {
  static entity = 'users'
  
  @Uid() declare id: string
  @Str('') declare name: string
  @Str('') declare email: string
}
  1. And this is my usage just like in the docs:
<template>
  <div>
    {{ users }}
  </div>

  <div>
    <button @click="addUser">
        Add user
    </button>
  </div>
</template>

<script setup lang="ts">
    import User from './stores/models/user'
    import { useRepo } from 'pinia-orm'

    const userRepo = useRepo(User)

    // Getting all users
    const users = userRepo.all()

    const addUser = () => {
        userRepo.insert({
            name: 'John Doe',
            email: '[email protected]'
        })
    }
</script>

Additional context

No response

Logs

No response

@CodeDredd CodeDredd added bug Something isn't working has workaround The issue contains a temporary solution to get around the problem and removed pending triage labels Sep 6, 2023
@CodeDredd
Copy link
Owner

CodeDredd commented Sep 6, 2023

@martinszeltins Thanks for the report. Don't know yet why this error happans.
With nuxt 3.6.5 this works. So somehow nuxt 3.7.1 still has somthing wrong.

Update:
Issue opened nuxt/nuxt#23038

@CodeDredd
Copy link
Owner

CodeDredd commented Sep 7, 2023

@martinszeltins Ok after some investigating i found a workaround for nuxt 3.7.1 . You can look there: nuxt/nuxt#23038 (comment)

@Sayanel34
Copy link

Still have this issue with a Many to Many relationship, no matter what i'm doing with vite and nuxt versions.

@ChrizzDF
Copy link

Just an FYI: It's also not solved by using Nuxt 3.8.0

@Sayanel34
Copy link

Yeah i didn't try it since i had other problems with this new version, but thanks for testing it.
I didn't try anything since my first post, i'll prob work on it within the week since it's blocking anyway.

@Sayanel34
Copy link

Did someone figure something out by any chance ?

@mariusgnicula
Copy link

mariusgnicula commented Nov 17, 2023

Nuxt 3.8.1 sadly doesn't have a fix for this either. The solution described here nuxt/nuxt#23038 seems to be the only workaround right now.

@mariusgnicula
Copy link

mariusgnicula commented Nov 19, 2023

Hey fellas! So I got this working with Nuxt 3.8.1 and Vite 5.0.0. Apparently it wasn't enough to add experimental decorators to my TS config, but add it to Nuxt config as well, like so:

export default defineNuxtConfig({
  debug: true,
  devtools: { enabled: true },
  modules: ['@pinia/nuxt', '@pinia-orm/nuxt'],
  typescript: {
    typeCheck: true,
    strict: true,
  },
  vite: {
    esbuild: {
      tsconfigRaw: {
        compilerOptions: {
          experimentalDecorators: true,
        }
      }
    }
  }
})

Got this workaround from here: vitejs/vite#13736

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working has workaround The issue contains a temporary solution to get around the problem nuxt 3
Projects
None yet
Development

No branches or pull requests

5 participants