question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

When using `@ignore` for some fields, there is no `create` method in the model

See original GitHub issue

Bug description

When using @ignore for some fields, there is no create method in the model. I’m ignoring just two fields but the rest should be available.

How to reproduce

Define this model:

model User {
  id        Int       @id @default(autoincrement())
  email     String    @unique
  password  String
  createdAt DateTime  @default(now()) @ignore
  updatedAt DateTime  @updatedAt @ignore
  remarks   String?
}

Then generate it. Then you cannot create a user using this code:

await this.prismaService.user.create({ data: newUser });

Because of this error:

Property 'create' does not exist on type 'UserDelegate<RejectOnNotFound | RejectPerOperation | undefined>'.ts(2339)

Expected behavior

The create method should be there!

Prisma information

Environment & setup

  • OS: Ubuntu 21.10
  • Database: PostgreSQL
  • Node.js version: 16.13.1

Prisma Version

3.8.1

Issue Analytics

  • State:closed
  • Created 2 years ago
  • Reactions:2
  • Comments:10 (8 by maintainers)

github_iconTop GitHub Comments

1reaction
janpiocommented, Sep 15, 2022

What do you think about me contributing …

Sounds good to me 👍

1reaction
AndrewSouthpawcommented, Sep 14, 2022

Maybe I’m not understanding how @ignore was designed to be used. @ignore would in theory achieve this desired outcome according to the docs, so it doesn’t feel like a feature is missing?

It seems like the bug goes away when the field is marked optional, FWIW.

// no `create`
model Test {
  id  Int    @id @default(autoincrement())
  foo String @ignore
}

// has `create`
model Test {
  id  Int    @id @default(autoincrement())
  foo String? @ignore
}
Read more comments on GitHub >

github_iconTop Results From Across the Web

Laravel - Ignoring fields that don't exist when using model
I can't make Laravel ignore fields that don't exist in the database when present in Eloquent's create method or when seeding the database....
Read more >
Jackson Ignore Properties on Marshalling - Baeldung
We can ignore specific fields at the class level, using the @JsonIgnoreProperties annotation and specifying the fields by name:
Read more >
How to ignore properties with System.Text.Json | Microsoft Learn
To ignore read-only fields when serializing fields, use the JsonSerializerOptions.
Read more >
3 ways to ignore null fields while converting Java object to ...
And, if that's precisely what you want, then you can ignore the fields with null values using @JsonInclude annotation in Jackson. Btw, if...
Read more >
How can we ignore the fields during JSON serialization in Java?
If there are fields in Java objects that do not wish to be serialized, we can use the @JsonIgnore annotation in the Jackson...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found