There's two errors in the code.

Tag.name field is not unique

From what I can infer from your domain, two tags should not have the same name. Furthermore, since the name field is not unique, you can't use it by itself to uniquely identify a specific Tag record and so Prisma will complain if you try to pass only the name field in the where condition of connectOrCreate.

The simplest and logical solution to this is to make the name field unique. Here's your updated Tag model

model Tag {
  id       Int       @id @default(autoincrement())
  name     String    @unique  // change
  articles Article[]
}

Incorrect syntax for connectOrCreate

You're passing separate arrays to the where and create fields. Instead, when you want to connect/create multiple records, pass an array of objects to connectOrCreate each with its own where and create field. Here's an example from the Prisma Docs that shows how to use connectOrCreate with multiple records.

This is what your create query should look like:

await prisma.article.create({
  data: {
    title,
    summary,
    link,
    archive,
    content,
    image,
    tags: {
        connectOrCreate: tags.map((tag) => {
            return {
                where: { name: tag },
                create: { name: tag },
            };
        }),
    },
  },
});
Answer from Tasin Ishmam on Stack Overflow
🌐
GitHub
github.com › prisma › prisma › discussions › 25186
connectOrCreate is great what about connectOrUpsert? · prisma/prisma · Discussion #25186
The upsert query is used to either update an existing User record or create a new one if it doesn't exist. The connectOrCreate nested query is used to connect the user to existing Post records or create new Post records if they don't exist.
Author   prisma
Discussions

How to use connectOrCreate with many to many
I want to use Prisma to associate articles with tags, that is: A post has multiple tags and a tag belongs to multiple posts But the example in Prisma will result in the creation of duplicate tags H... More on github.com
🌐 github.com
2
1
differences between connectOrCreate and upsert?
We also chose the wording for connectOrCreate in a way that it's intuitively clear what's happening: Fist we try to connect to the record specified by where. If the record does not exist, we create a new one. Functionality-wise, they're indeed similar but we chose a bit more precise wording for this one to make it easier to understand. On a technical level, the two are also different and take different input arguments: await prisma... More on github.com
🌐 github.com
2
5
Use connectOrCreate for nested fields and relationships.
I am using connectOrCreate to avoid duplicate relationships. When using connectOrCreate you first find if a relationship already exists (using where), and if it doesn't you create it. The where clause inside connectOrCreate can only compare towards a unique field (such as a id). More on github.com
🌐 github.com
2
1
connectOrCreate multiple records issue
The issue here is that tasks.tags is actually of type TagsOnTasks, not Tags. This means the where property of your connectOrCreate should look like this to satisfy the TagsOnTasksWhereUniqueInput type in the error message: More on github.com
🌐 github.com
4
1
🌐
Paigeniedringhaus
paigeniedringhaus.com › blog › tips-and-tricks-for-using-the-prisma-orm
Tips and Tricks for Using the Prisma ORM | Paige Niedringhaus
According to Prisma’s docs, the connectOrCreate API function is the way to create a “related record” that may or may not exist, which is perfect for adding new devices to the Device table and new, related fleets to the Fleet table at the ...
🌐
Prisma
prisma.io › home › prisma client api › prisma client api › prisma client api
Prisma Client API | Prisma Documentation
connectOrCreate either connects a record to an existing related record by ID or unique identifier or creates a new related record if the record does not exist.
🌐
Prisma
prisma.io › home › crud › crud › crud › crud
CRUD (Reference) | Prisma Documentation
const u = await prisma.user.create({ ... [ { title: "My first post", categories: { connectOrCreate: [ { create: { name: "Introductions" }, where: { name: "Introductions", }, }, { create: ......
Find elsewhere
🌐
GitHub
github.com › prisma › prisma › discussions › 12059
connectOrCreate multiple records issue · prisma/prisma · Discussion #12059
The issue here is that tasks.tags is actually of type TagsOnTasks, not Tags. This means the where property of your connectOrCreate should look like this to satisfy the TagsOnTasksWhereUniqueInput type in the error message:
Author   prisma
🌐
GitHub
github.com › prisma › prisma › issues › 4747
ID when use `upsert`, `connectOrCreate` and things like that · Issue #4747 · prisma/prisma
December 21, 2020 - this.prisma.blogs.update({ where: { id: req.body.id }, data: { title: req.body.title, text: req.body.text, images: { connect: { id: req.body.images_id } }, embed: req.body.embed, embedType: req.body.embedType, categories: { connect: { id: req.body.categories_id } }, sources: { connectOrCreate: req.body.sources.map((source: any) => { return { where: { id: source.id ?
Author   prisma
🌐
Linen
linen.dev › s › prisma › t › 2354064 › query-const-newdata-answers-type-workflowtype-historic-creat
can i do a nested `connectOrCreate` from within an `upsert` Prisma #orm-help
const newData = { answers, type: WorkflowType.Historic, creator: { connectOrCreate: { create: { email: creatorEmail, }, where: { email: creatorEmail, }, }, }, } const id = deterministicId(newData) await db.workflow.upsert({ where: { id, }, update: newData, create: { id, ...newData, }, }) simplified models:
🌐
GitHub
github.com › prisma › prisma › issues › 5100
Support for multiple connects or creations in `connectOrCreate` · Issue #5100 · prisma/prisma
January 4, 2021 - Problem Currently the connectOrCreate field, only gives you the ability to connect or create one record. Suggested solution For the connectOrCreate fields: where and create, to be a prisma Enuremable, like the normal create and connect f...
Author   prisma
🌐
Answer Overflow
answeroverflow.com › m › 1310471436300845076
Using OR in connectOrCreate - Prisma
November 25, 2024 - PrismaJoinThe official Discord server of Prisma! Find us online at prisma.io ... Type '{ connectOrCreate: { where: { state_name: string; }; create: { state_name: string; }; }; }' is
🌐
Stack Overflow
stackoverflow.com › questions › 76829241 › connectorcreate-in-createmany-prisma-query
connectOrCreate in createMany prisma query? - Stack Overflow
https://github.com/prisma/prisma/issues/5455 · You can loop over your records and use create with connectOrCreate. Share · Improve this answer · Follow · answered Aug 3, 2023 at 18:20 · Nurul Sundarani · 7,94833 gold badges3939 silver badges6262 bronze badges ·