Could you share the schema file and query here in ...
# random
n
Could you share the schema file and query here in text format? It’s difficult to copy it from the screenshot. 😅
a
model user { id Int @id @default(autoincrement()) name String email String @unique password String phoneNo Int is_Agreed Boolean? role RoleEnumType? @default(USER) createdAt DateTime @default(now()) updatedAt DateTime @updatedAt chits UserOnChit[] loans loan[] loan_transactions loan_transaction[] bids bid[] results result[] payment_details payment_details[] } enum RoleEnumType { USER ADMIN } model chit { id Int @id @default(autoincrement()) name String description String chit_amt Int monthly_amount Int month_due_date DateTime @db.Date no_of_users Int auction_date DateTime @db.Date start_date DateTime @db.Date end_date DateTime @db.Date createdAt DateTime @default(now()) updatedAt DateTime @updatedAt deletedAt DateTime? users UserOnChit[] wallets wallet[] bids bid[] results result[] payment_details payment_details[] } model UserOnChit { user user @relation(fields: [userId], references: [id]) userId Int chit chit @relation(fields: [chitId], references: [id]) chitId Int assignedAt DateTime @default(now()) @@id([userId, chitId]) }
const chit = await prisma.chit.update({ where: { id: 1 }, data: { users: { connect: { id: 2 } } } })
how i connect explicit many to many on existing data
n
You could use a query like this:
Copy code
const chit = await prisma.chit.update({
    where: {
      id: 1,
    },
    data: {
      users: {
        connect: {
          userId_chitId: {
            chitId: 1,
            userId: 1,
          },
        },
      },
    },
  });
a
Thank you for your help 😁 its actually shown an error like this!!! "Expected 1 records to be connected after connect operation on one-to-many relation '*UserOnChitTochit'*, found 0."
n
This error would mean that the records which you are trying to connect were not found. Can you check if the records which you are connecting exists?
a
yes one record in user table and another in chit table with id 1
any help on this?
n
To me this looks like data issue because the query is working for me, can you try creating a new user and a new chit and then try to connect them?
a
ok let me try
"Expected 1 records to be connected after connect operation on one-to-many relation 'UserOnChitTochit', found 0." got the same error
n
That’s strange, is your code perhaps open source? If yes, could you share the repository?