#Prisma createMany connect many. What am I doing wrong?

1 messages · Page 1 of 1 (latest)

heavy heart
#

seed.ts

const prisma = new PrismaClient();

async function seed() {
  await prisma.tag.deleteMany();
  await prisma.event.deleteMany();

  // initialize pre-defined tags
  await prisma.tag.createMany({
    data: Array.from(Object.values(tags), (tags) => {
      return Array.from(tags, ({ title, color }) => ({ title, color }));
    }).flat(),
  });

  const seededTags = await prisma.tag.findMany();
  

  // This works
  await prisma.event.create({
    data: {
      address: "",
      city: "",
      attendees: 0,
      creator: "",
      date: new Date(),
      description: "",
      duration: 0,
      name: "",
      state: "",
      zip: "",
      tags: { connect: [{ id: seededTags[0].id }] },
    },
  });

  // This gives me an error
  await prisma.event.createMany({
    data: Array.from({ length: 100 }, () => {
      return {
        attendees: faker.number.int(100),
        description: faker.lorem.paragraphs(1),
        name: faker.lorem.words(faker.number.int({ min: 1, max: 6 })),
        creator: faker.person.fullName(),
        date: faker.date.anytime(),
        address: faker.location.streetAddress(),
        city: faker.location.city(),
        duration: faker.number.int({ min: 1, max: 8 }),
        state: faker.location.state({ abbreviated: true }),
        zip: faker.location.zipCode(),
        tags: {
          connect: faker.helpers
            .arrayElements(seededTags, faker.number.int(10))
            .map(({ id }) => ({ id })),
        },
      };
    }),
  });
}

seed()
  .then(async () => {
    await prisma.$disconnect();
  })

  .catch(async (e) => {
    console.error(e);

    await prisma.$disconnect();

    process.exit(1);
  });
#

error when running seed.ts

          ...
          {
            attendees: 89,
            description: "Arx candidus cado. Coruscus suasoria conatus unde traho cohibeo deprecator adhaero. Solio arx truculenter ducimus suppono cibo strues corroboro.",
            name: "tristis",
            creator: "Faith Prosacco PhD",
            date: new Date("2023-10-14T03:40:42.081Z"),
            address: "51282 Fritz Rue",
            city: "McClureborough",
            duration: 1,
            state: "MD",
            zip: "95926",
            tags: {
              connect: [
                {
                  id: "6596f55ba52786e1d3ee9654"
                },
                {
                  id: "6596f55ba52786e1d3ee9650"
                },
              ]
            }
          }
        ]
      })

Unknown argument `tags`. Did you mean `tagIds`? Available options are marked with ?.
    at ti (/Users/user/Documents/GitHub/whats-happening/node_modules/@prisma/client/runtime/library.js:118:5888)
    at si.handleRequestError (/Users/user/Documents/GitHub/whats-happening/node_modules/@prisma/client/runtime/library.js:125:6473)
    at si.handleAndLogRequestError (/Users/user/Documents/GitHub/whats-happening/node_modules/@prisma/client/runtime/library.js:125:6151)
    at si.request (/Users/user/Documents/GitHub/whats-happening/node_modules/@prisma/client/runtime/library.js:125:5859)
    at async l (/Users/user/Documents/GitHub/whats-happening/node_modules/@prisma/client/runtime/library.js:130:10025)
    at seed (/Users/user/Documents/GitHub/whats-happening/prisma/seed.ts:116:3) {
  clientVersion: '5.7.1'
}

An error occurred while running the seed command:
Error: Command failed with exit code 1: tsx prisma/seed.ts
#

this works