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

Primary key cannot be explicitly set in enhanced create when using extended models #1518

Closed
KilianSL opened this issue Jun 17, 2024 · 1 comment · Fixed by #1521
Closed

Comments

@KilianSL
Copy link

Description
The id field inherited from the parent model cannot be explicitly set when the enhanced create method is called on a "concrete" model. In my project, I have a model Activity, which declares the field id String @id @db.Uuid @default(uuid()), alongside some other shared fields. This model is then extended into a number of other models (i.e. VideoActivity). When calling the enhanced create action against one of the child models, if the id field is specified as part of the create, the action fails with error Unknown argument 'id'.

This bug can be worked around by not specifying the id field in the create call, and instead relying on the @default characteristic to generate a uuid for the entity, however this is not desirable in all cases.

Expected Behaviour
Inlcuding a valid UUID in the create request should insert a row into the database with the provided UUID, overriding the default value.

Screenshots
Minimal code snippets to reproduce the bug:

schema.zmodel

enum ActivityType {
  TaskActivity
}
model Activity {
  id        String       @id @db.Uuid @default(uuid())
  title     String
  type      ActivityType
  @@delegate(type)
  @@allow('all', true)
}
model TaskActivity extends Activity {
  description String
  @@map("task_activity")
  @@allow('all', true)
}

seed.ts

const client = new PrismaClient();
const prisma = enhance(client);
await prisma.taskActivity.create({
      data: {
        id: '00000000-0000-0000-0000-111111111111',
        title: 'Test Activity',
        description: 'Description of task',
      },
    });

Environment:

  • ZenStack version: 2.2.3
  • Prisma version: 5.15.0
  • Database type: Postgresql
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
2 participants