Why am I getting undefined type? ```const transact...
# orm-help
p
Why am I getting undefined type?
Copy code
const transaction = prisma.transaction.create({
    data: {
      audience,
      description,
      paymentMethodId: '',
      type: 'TRANSFER',
      balances: {
        create: [
          {
            amount,
            accountId: payeeId,
            currency: 'GPT',
          },
          {
            amount: amount * -1,
            accountId: payorId,
            currency: 'GPT',
          },
        ],
      },
      transfer: {
        create: {
          payeeId,
          payorId,
        },
      },
       accounts: {
        connect: [
          {
            id: '',
          },
          {
            id: '',
          },
        ],
      },
    },
  });
And this is my schema for transaction and account:
Copy code
model Transaction {       
  accounts                    Account[]
}


model Account {
  transactions                Transaction[] 
}
This is my error:
Copy code
Type '{ audience: AUDIENCE; description: string; paymentMethodId: string; type: "TRANSFER"; balances: { create: { amount: number; accountId: string; currency: "GPT"; }[]; }; transfer: { create: { ...; }; }; accounts: { ...; }; }' is not assignable to type '(Without<TransactionCreateInput, TransactionUncheckedCreateInput> & TransactionUncheckedCreateInput) | (Without<...> & TransactionCreateInput)'.
  Type '{ audience: AUDIENCE; description: string; paymentMethodId: string; type: "TRANSFER"; balances: { create: { amount: number; accountId: string; currency: "GPT"; }[]; }; transfer: { create: { ...; }; }; accounts: { ...; }; }' is not assignable to type 'Without<TransactionUncheckedCreateInput, TransactionCreateInput> & TransactionCreateInput'.
    Type '{ audience: AUDIENCE; description: string; paymentMethodId: string; type: "TRANSFER"; balances: { create: { amount: number; accountId: string; currency: "GPT"; }[]; }; transfer: { create: { ...; }; }; accounts: { ...; }; }' is not assignable to type 'Without<TransactionUncheckedCreateInput, TransactionCreateInput>'.
      Types of property 'paymentMethodId' are incompatible.
        Type 'string' is not assignable to type 'undefined'.
🥲 1
c
@prisma chobo did you figure this out? I’m running into a similar issue with implicit many-to-many.
p
No….. this is frustrating 😞 please share me if you happen to figure out
c
@prisma chobo I wasn’t able to figure it out either. Also the official docs has typos. I think I may end up doing an explicit many to many.
r
@Code Coffee 👋 Could you point out what typos the official docs have? Also @prisma chobo can you share your entire schema so that I can check?
c
@Ryan If you go to the
explicit many to many
example here: https://www.prisma.io/docs/support/help-articles/working-with-many-to-many-relations It says it would be a create to the
PostTags
but the example does a create to
post
r
It seems correct as the example is for explicit many-to-many relations. So the query will create entries in the relation table i.e.
PostTags
and also the
Tag
table. The
tags: { create: [] }
does this.
c
ah I think the way it was worded was a bit confusing.
I get what it’s saying now.
@Ryan are there any examples in the docs that shows how to query the relation model directly? I just saw nested queries examples here: https://www.prisma.io/docs/concepts/components/prisma-schema/relations/many-to-many-relations
I also went to Prisma Examples: https://github.com/prisma/prisma-examples but those schemas are all one to many.
r
You can only query the relation model in explicit many-to-many relation. For implicit relations that’s not possible.
You can have a look at this doc that explains it.
c
okay to be clear,
post.create
and the
tags: { create: [] }
is what is considered querying the relation model? And in no situation do we ever do a
PostTags.create
?
I think that’s where I was confused at if that’s the case.
r
It’s possible to do it but a situation would never arise to do
PostTags.create
. Tags can be created connected via
Post
when your can create them.
c
okay thanks for clearing that up!
🙌 1
p
@Ryan Hello Ryan this is my schema
Copy code
model Account {
  id                          String                      @id @default(cuid())
  type                        ACCOUNT_TYPE                @default(PERSONAL)
  userId                      String?                     @map("user")
  username                    String                      @unique
  // *************** RELATIONS *****************
  balances                    Balance[]
  collections                 Transfer[]                  @relation("Collections")
  followers                   Account[]                   @relation("AccountFollows", references: [id])
  following                   Account[]                   @relation("AccountFollows", references: [id])
  funds                       Fund[]
  payments                    Transfer[]                  @relation("Payments")
  paymentMethods              PaymentMethod[]
  payouts                     Payout[]
  profile                     Profile?
  transactions                Transaction[]               
  user                        User?                       @relation(fields: [userId], references: [id])
  // *******************************************
  createdAt                   DateTime                    @default(now())                   
  updatedAt                   DateTime                    @default(now()) 
  deletedAt                   DateTime?
}


model Transaction {
  id                          String                      @id @default(cuid()) 
  audience                    AUDIENCE                    @default(PRIVATE)
  description                 String
  exchangeRate                Float? 
  status                      TRANSACTION_STATUS          @default(PENDING)
  type                        TRANSACTION_TYPE
  // *************** RELATIONS *****************               
  accounts                    Account[]
  balances                    Balance[]             
  fund                        Fund?                     
  fees                        Fee[]
  payout                      Payout?           
  transfer                    Transfer?          
  // *******************************************
  createdAt                   DateTime                    @default(now())                   
  updatedAt                   DateTime                    @default(now()) 
  deletedAt                   DateTime?
}
r
You still haven’t provided the entire schema as per your query: https://prisma.slack.com/archives/CA491RJH0/p1626814651287900