0

I've been stuck on this problem for hours.

I'm trying to create an object linked by a many to many relationship. However, I get this error when the function is invoked:

Unknown arg 0 in data.merchandises.create.0 for type ListingsMerchandisesCreateWithoutListingInput. Argument merchandise for data.merchandises.create.merchandise is missing.

I don't know where that "0" comes from.

Thank you in advance for your help..

Full log of error:

 Invalid `prisma[prismaModel].create()` invocation in
    /app/node_modules/prisma-factory/dist/index.js:109:44

      106   data = hooks.beforeCreate(data);
      107 }
      108 const prismaModel = (0, import_camel_case.camelCase)(modelName);
    → 109 let result = await prisma[prismaModel].create({
            data: {
              type: 'FOR_RENT',
              name: 'consequatur',
              merchandises: {
                create: {
                  '0': {
                    merchandise: {
                      create: {
                        cosmetic: 'GOOD',
                        typology: 'NEW',
                        quantity: 76,
                        price: 80,
                        location: {
                          create: {
                            name: 'repellat',
                            line1: '600 Jerde Mews',
                            line2: 'Apt. 517',
                            line3: '79414 Lenore Harbor',
                            line4: 'placeat',
                            city: 'Port Astridshire',
                            postalCode: '47459-8067',
                            state: 'North Carolina',
                            country: 'Antigua and Barbuda',
                            other: 'iste'
                          }
                        },
                        user: {
                          create: {
                            email: 'Neoma41@gmail.com',
                            firstName: 'Casimir',
                            lastName: 'Kub'
                          }
                        },
                        product: {
                          create: {
                            name: 'Luxurious Steel Keyboard',
                            description: 'The Nagasaki Lander is the trademarked name of several series of Nagasaki sport bikes, that started with the 1984 ABC800J',
                            barcode: 'r0h7w9h1d',
                            barcodeType: 'EAN13',
                            brand: 'Bespoke',
                            model: 'Countach',
                            lenght: 25,
                            width: 57,
                            weight: 11,
                            capacity: 62,
                            impactUnit: 'UNIT',
                            manufacturingImpact: 31,
                            destructiveImpact: 81
                          }
                        }
                      }
                    }
                  },
          +       merchandise: {
          +         create?: MerchandiseCreateWithoutListingsInput | MerchandiseUncheckedCreateWithoutListingsInput,
          +         connectOrCreate?: MerchandiseCreateOrConnectWithoutListingsInput,
          +         connect?: MerchandiseWhereUniqueInput
          +       }
                }
              }
            }
          })

    Unknown arg `0` in data.merchandises.create.0 for type ListingsMerchandisesCreateWithoutListingInput.
    Argument merchandise for data.merchandises.create.merchandise is missing.

The factory:

import { createFactory } from 'prisma-factory';
import { faker } from '@faker-js/faker';
import {
  BarcodeType,
  Cosmetic,
  ImpactUnit,
  Listing,
  ListingType,
  Prisma,
  Typology,
} from '@prisma/client';

const DEFAULT_ATTRIBUTES = {
  type: ListingType.FOR_RENT,
  name: faker.lorem.word(),
  merchandises: {
    create: [
      {
        merchandise: {
          create: {
            cosmetic: Cosmetic.GOOD,
            typology: Typology.NEW,
            quantity: Number(faker.random.numeric(2)),
            price: Number(faker.random.numeric(2)),
            location: {
              create: {
                name: faker.lorem.word(),
                line1: faker.address.streetAddress(),
                line2: faker.address.secondaryAddress(),
                line3: faker.address.streetAddress(),
                line4: faker.lorem.word(),
                city: faker.address.city(),
                postalCode: faker.address.zipCode(),
                state: faker.address.state(),
                country: faker.address.country(),
                other: faker.lorem.word(4),
              },
            },
            user: {
              create: {
                email: faker.internet.email(),
                firstName: faker.name.firstName(),
                lastName: faker.name.lastName(),
              },
            },
            product: {
              create: {
                name: faker.commerce.productName(),
                description: faker.commerce.productDescription(),
                barcode: faker.random.alphaNumeric(9),
                barcodeType: BarcodeType.EAN13,
                brand: faker.commerce.productAdjective(),
                model: faker.vehicle.model(),
                lenght: Number(faker.random.numeric(2)),
                width: Number(faker.random.numeric(2)),
                weight: Number(faker.random.numeric(2)),
                capacity: Number(faker.random.numeric(2)),
                impactUnit: ImpactUnit.UNIT,
                manufacturingImpact: Number(faker.random.numeric(2)),
                destructiveImpact: Number(faker.random.numeric(2)),
              },
            },
          },
        },
      },
    ],
  },
};

export const ListingFactory = createFactory<Prisma.ListingCreateInput, Listing>(
  'listing',
  DEFAULT_ATTRIBUTES,
);

concerning schema:

model Listing {
  id           Int                    @id @default(autoincrement())
  type         ListingType
  name         String
  merchandises ListingsMerchandises[]
  availability Availability?
  category     Category?              @relation(fields: [categoryId], references: [id])
  categoryId   Int?
  createdAt    DateTime               @default(now())
  updatedAt    DateTime               @updatedAt
  deletedAt    DateTime?
}

model Merchandise {
  id         Int                    @id @default(autoincrement())
  cosmetic   Cosmetic
  typology   Typology
  quantity   Int
  price      Int
  productId  Int
  product    Product                @relation(fields: [productId], references: [id])
  userId     Int
  user       User                   @relation(fields: [userId], references: [id])
  locationId Int
  location   Location?              @relation(fields: [locationId], references: [id])
  listings   ListingsMerchandises[]
  createdAt  DateTime               @default(now())
  updatedAt  DateTime               @updatedAt
  deletedAt  DateTime?
}

model ListingsMerchandises {
  listingId     Int
  listing       Listing     @relation(fields: [listingId], references: [id])
  merchandiseId Int
  merchandise   Merchandise @relation(fields: [merchandiseId], references: [id])

  @@id([listingId, merchandiseId])
}

I tried several formats, I even tried a connect but without success. No type errors are thrown

Fizzy-59
  • 31
  • 3

0 Answers0