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

@ignore on required fields disables create and update operations on model #13467

Closed
jonsandg opened this issue May 24, 2022 · 4 comments
Closed
Labels
bug/1-unconfirmed Bug should have enough information for reproduction, but confirmation has not happened yet. kind/bug A reported bug. team/client Issue for team Client.

Comments

@jonsandg
Copy link

jonsandg commented May 24, 2022

Bug description

According to docs:

You can manually add @ignore to a field that you want to exclude from the Prisma Client (for example, a field that you do not want Prisma users to update)

When you set @ignore on required fields the client generation does not create the functions for create, update, upsert, etc., for the model. I realize this might be intended behavior. If so the docs could probably use some clarifications on @ignore and I would love some pointers on how to get around the problem.

For context, I'm trying to get prisma working with temporal tables, which requires the table to have two non-nullable datetime fields which are set by the database. If I set the fields to be nullable with a ? the client generation works as I expect but then prisma migrate will try to change the fields to be nullable. More here

How to reproduce

datasource db {
  provider = "sqlserver"
  url      = env("DATABASE_URL")
}

generator client {
  provider = "prisma-client-js"
}

model TestModel {
  id         String  @id @default(uuid())
  name       String
  ignorethis String @ignore
}

npx prisma generate and run:

const { PrismaClient } = require('@prisma/client');

const prisma = new PrismaClient();

prisma.testModel
  .create({
    data: { name: 'lala' },
  })
  .then(res => console.log(res));

Gives error: TypeError: prisma.testModel.create is not a function

Expected behavior

Be able to use functions like create, createMany, update, etc. on the model

Prisma information

Environment & setup

  • OS: Mac
  • Database: SQL server
  • Node.js version: v16.13.2

Prisma Version

prisma                  : 3.14.0
@prisma/client          : 3.14.0
Current platform        : darwin-arm64
Query Engine (Node-API) : libquery-engine 2b0c12756921c891fec4f68d9444e18c7d5d4a6a (at node_modules/@prisma/engines/libquery_engine-darwin-arm64.dylib.node)
Migration Engine        : migration-engine-cli 2b0c12756921c891fec4f68d9444e18c7d5d4a6a (at node_modules/@prisma/engines/migration-engine-darwin-arm64)
Introspection Engine    : introspection-core 2b0c12756921c891fec4f68d9444e18c7d5d4a6a (at node_modules/@prisma/engines/introspection-engine-darwin-arm64)
Format Binary           : prisma-fmt 2b0c12756921c891fec4f68d9444e18c7d5d4a6a (at node_modules/@prisma/engines/prisma-fmt-darwin-arm64)
Default Engines Hash    : 2b0c12756921c891fec4f68d9444e18c7d5d4a6a
Studio                  : 0.460.0
@jonsandg jonsandg added the kind/bug A reported bug. label May 24, 2022
@pantharshit00
Copy link
Contributor

@ignore will only disable the create/update operation on required fields so if you add a ? to the field, it will re-enable the operation. I agree this feature requires some documentation improvement.

@jkomyno jkomyno added team/client Issue for team Client. bug/1-unconfirmed Bug should have enough information for reproduction, but confirmation has not happened yet. labels May 25, 2022
@garrensmith
Copy link
Contributor

hey @jonsandg thanks for the error report. This is intended behaviour.

@andrew-walford-prisma could you take a look at this. This is intended behaviour but I think we should improve the docs around this. @Weakky can help with the explanation

@dpetrick dpetrick closed this as completed Jul 8, 2022
@tombohub
Copy link

tombohub commented Nov 5, 2022

@garrensmith
I think you should allow @updatedAt field to have @ignore, without losing create etc. functions

@maxh
Copy link

maxh commented Aug 4, 2023

We've added a rule forbid-required-ignored-field to prisma-lint to detect this case:

https://github.com/loop-payments/prisma-lint/blob/main/RULES.md#forbid-required-ignored-field

This helps avoid confusion on our team. Might help others who find this issue as well.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug/1-unconfirmed Bug should have enough information for reproduction, but confirmation has not happened yet. kind/bug A reported bug. team/client Issue for team Client.
Projects
None yet
Development

No branches or pull requests

7 participants