Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(docs): Update create vs createMany with recent changes. #6006

Merged
merged 10 commits into from
May 24, 2024
4 changes: 2 additions & 2 deletions .github/workflows/check-all-links.yml
Original file line number Diff line number Diff line change
Expand Up @@ -63,13 +63,13 @@ jobs:
run: npm install

- name: Install remark presets
run: npm install remark-lint-no-dead-urls
run: npm install remark-lint-no-dead-urls remark-custom-header-id

- name: run remark-cli
env:
BRANCH_NAME: ${{ github.head_ref || github.ref_name }}
run: |
npx remark-cli . -qf -e=md,mdx --use=remark-mdx --use remark-frontmatter --use remark-gfm \
npx remark-cli . -qf -e=md,mdx --use remark-mdx --use remark-custom-header-id --use remark-frontmatter --use remark-gfm \
--use "remark-lint-no-dead-urls=skipLocalhost:true,skipUrlPatterns:['https://www.notion.so/prismaio','https://www.prisma.io/docs','https://dash.cloudflare.com','https://www.cloudflare.com']"

check-for-dead-internal-links:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -535,16 +535,14 @@ There are two ways to create or update a single record and multiple related reco
- Use a nested [`create`](/orm/reference/prisma-client-reference#create-1) query
- Use a nested [`createMany`](/orm/reference/prisma-client-reference#createmany-1) query

Each technique has pros and cons:
In most cases, a nested `create` will be preferable unless the [`skipDuplicates` query option](/orm/reference/prisma-client-reference#nested-createmany-options) is required. Here's a quick table describing the differences between the two options:

| Feature | `create` | `createMany` | Notes |
| :------------------------------------ | :------- | :----------- | :---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
| Creates one record at a time | ✔ | ✘ | Potentially less performant. |
| Creates all records in one query | ✘ | ✔ | Potentially more performant. |
| Supports nesting additional relations | ✔ | ✘ \* | For example, you can create a user, several posts, and several comments per post in one query.<br />\* You can manually set a foreign key in a has-one relation - for example: `{ authorId: 9}` |
| Supports 1-n relations | ✔ | ✔ | For example, you can create a user and multiple posts (one user has many posts) |
| Supports m-n relations | ✔ | ✘ | For example, you can create a post and several categories (one post can have many categories, and one category can have many posts) |
| Supports skipping duplicate records | ✘ | ✔ | Use `skipDuplicates` query option. |
| Supports has-many relations | ✔ | ✔ | For example, you can create a user and multiple posts (one user has many posts) |
| Supports many-to-many relations | ✔ | ✘ | For example, you can create a post and several categories (one post can have many categories, and one category can have many posts) |

#### Using nested `create`

Expand Down
6 changes: 3 additions & 3 deletions content/200-orm/500-reference/050-prisma-client-reference.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -2855,7 +2855,7 @@ A nested `create` query adds a new related record or set of records to a parent
#### Remarks

- `create` is available as a nested query when you `create()` (`prisma.user.create(...)`) a new parent record or `update()` (`prisma.user.update(...)`) an existing parent record.
- You can use a nested `create` _or_ a nested [`createMany`](#createmany-1) to create multiple related records - [each technique pros and cons](/orm/prisma-client/queries/relation-queries#create-a-single-record-and-multiple-related-records).
- You can use a nested `create` _or_ a nested [`createMany`](#createmany-1) to create multiple related records. If you require the [`skipDuplicates` query option](#nested-createmany-options) you should use `createMany`.

#### Examples

Expand Down Expand Up @@ -2960,9 +2960,9 @@ A nested `createMany` query adds a new set of records to a parent record. See: [
- You cannot nest an additional `create` or `createMany`.
- Allows setting foreign keys directly — for example, setting the `categoryId` on a post.
- As of Prisma ORM version 5.12.0, nested `createMany` is supported by SQLite.
- You can use a nested `create` _or_ a nested `createMany` to create multiple related records - [each technique pros and cons](/orm/prisma-client/queries/relation-queries#create-a-single-record-and-multiple-related-records).
- You can use a nested `create` _or_ a nested `createMany` to create multiple related records - [if you do not need the `skipDuplicates` query option, you should probably use `create`](/orm/prisma-client/queries/relation-queries#create-a-single-record-and-multiple-related-records).

#### Options
#### Options \{#nested-createmany-options}

| Name | Type | Required | Description |
| ----------------- | --------------------------------- | -------- | ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
Expand Down
Loading