Skip to content

Commit

Permalink
Merge branch 'misc/add-visual' of github.com:prisma/docs into misc/ad…
Browse files Browse the repository at this point in the history
…d-visual
  • Loading branch information
nikolasburk committed Jul 3, 2024
2 parents 410fc26 + ca0fd26 commit 28942a1
Show file tree
Hide file tree
Showing 6 changed files with 16 additions and 57 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -295,7 +295,7 @@ model Category {

<Admonition type="info">

This schema is the same as the [example data model](/orm/prisma-schema/data-model/models) but has all [scalar fields](/orm/prisma-schema/data-model/models#scalar-fields) removed (except for the required [relation scalars](/orm/prisma-schema/data-model/relations#relation-scalar-fields)) so you can focus on the [relation fields](#relation-fields).
This schema is the same as the [example data model](/orm/prisma-schema/data-model/models) but has all [scalar fields](/orm/prisma-schema/data-model/models#scalar-fields) removed (except for the required [relation scalar fields](/orm/prisma-schema/data-model/relations#relation-scalar-fields)) so you can focus on the [relation fields](#relation-fields).

</Admonition>

Expand Down Expand Up @@ -337,7 +337,7 @@ If you're not using Prisma Migrate but obtain your data model from [introspectio

Relation [fields](/orm/prisma-schema/data-model/models#defining-fields) are fields on a Prisma [model](/orm/prisma-schema/data-model/models#defining-models) that do _not_ have a [scalar type](/orm/prisma-schema/data-model/models#scalar-fields). Instead, their type is another model.

Every relation must have exactly two relation fields, one on each model. In the case of one-to-one and one-to-many relations, an additional _relation scalar field_ is required which gets linked by one of the two relation fields in the `@relation` attribute. This relation scalar is the direct representation of the _foreign key_ in the underlying database.
Every relation must have exactly two relation fields, one on each model. In the case of one-to-one and one-to-many relations, an additional _relation scalar field_ is required which gets linked by one of the two relation fields in the `@relation` attribute. This relation scalar field is the direct representation of the _foreign key_ in the underlying database.

<TabbedContent code>

Expand All @@ -348,13 +348,13 @@ model User {
id Int @id @default(autoincrement())
email String @unique
role Role @default(USER)
posts Post[]
posts Post[] // relation field (defined only at the Prisma ORM level)
}
model Post {
id Int @id @default(autoincrement())
title String
author User @relation(fields: [authorId], references: [id])
author User @relation(fields: [authorId], references: [id]) // relation field (uses the relation scalar field `authorId` below)
authorId Int // relation scalar field (used in the `@relation` attribute above)
}
```
Expand All @@ -367,56 +367,23 @@ model User {
id String @id @default(auto()) @map("_id") @db.ObjectId
email String @unique
role Role @default(USER)
posts Post[]
posts Post[] // relation field (defined only at the Prisma ORM level)
}
model Post {
id String @id @default(auto()) @map("_id") @db.ObjectId
title String
author User @relation(fields: [authorId], references: [id])
author User @relation(fields: [authorId], references: [id]) // relation field (uses the relation scalar field `authorId` below)
authorId String @db.ObjectId // relation scalar field (used in the `@relation` attribute above)
}
```

</TabItem>
</TabbedContent>

These models have the following fields:

<TabbedContent>
<TabItem value="Relational databases">

| Model | Field | Relational | Relation field |
| :----- | :--------- | :--------- | :--------------------------- |
| `User` | `id` | `Int` | No |
| | `email` | `String` | No |
| | `role` | `Role` | No |
| | `posts` | `Post[]` | **Yes** (Prisma ORM-level) |
| `Post` | `id` | `Int` | No |
| | `title` | `String` | No |
| | `authorId` | `Int` | No (_relation scalar field_) |
| | `author` | `User` | **Yes** (_annotated_) |

</TabItem>
<TabItem value="MongoDB">

| Model | Field | Relational | Relation field | Notes |
| :----- | :--------- | :--------- | :--------------------------- | -------------------------------------- |
| `User` | `id` | `String` | No | Underlying database type is `ObjectId` |
| | `email` | `String` | No |
| | `role` | `Role` | No |
| | `posts` | `Post[]` | **Yes** (Prisma ORM-level) |
| `Post` | `id` | `String` | No |
| | `title` | `String` | No |
| | `authorId` | `String` | No (_relation scalar field_) | Underlying database type is `ObjectId` |
| | `author` | `User` | **Yes** (_annotated_) |

</TabItem>
</TabbedContent>

Both `posts` and `author` are relation fields because their types are not scalar types but other models.

Also note that the annotated relation field `author` needs to link the relation scalar field `authorId` on the `Post` model inside the `@relation` attribute. The relation scalar represents the foreign key in the underlying database.
Also note that the [annotated relation field](#annotated-relation-fields) `author` needs to link the relation scalar field `authorId` on the `Post` model inside the `@relation` attribute. The relation scalar field represents the foreign key in the underlying database.

The other relation field called `posts` is defined purely on a Prisma ORM-level, it doesn't manifest in the database.

Expand Down Expand Up @@ -453,13 +420,7 @@ A scalar field _becomes_ a relation scalar field when it's used in the `fields`

### Relation scalar fields

<Admonition type="info">

Relation scalar fields are read-only in the generated [Prisma Client API](/orm/prisma-client). If you want to update a relation in your code, you can do so using [nested writes](/orm/prisma-client/queries/relation-queries#nested-writes).

</Admonition>

#### Relation scalar naming conventions
#### Relation scalar field naming conventions

Because a relation scalar field always _belongs_ to a relation field, the following naming convention is common:

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ By default, when a query returns records (as opposed to a count), the result inc

To customize the result:

- Use [`select`](/orm/reference/prisma-client-reference#select) to return specific fields - [you can also use a nested `select` to include relation fields](/orm/prisma-client/queries/relation-queries#select-specific-relation-fields)
- Use [`select`](/orm/reference/prisma-client-reference#select) to return specific fields - [you can also use a nested `select` to include relation fields](/orm/prisma-client/queries/relation-queries#select-specific-fields-of-included-relations)
- Use [`include`](/orm/reference/prisma-client-reference#include) to explicitly [include relations](/orm/prisma-client/queries/relation-queries#nested-reads)

Selecting only the fields and relations that you require rather than relying on the default selection set can ✔ reduce the size of the response and ✔ improve query speed.
Expand Down Expand Up @@ -314,7 +314,7 @@ const users = await prisma.user.findMany({
For more information about querying relations, refer to the following documentation:

- [Include a relation (including all fields)](/orm/prisma-client/queries/relation-queries#include-all-fields-for-a-specific-relation)
- [Select specific relation fields](/orm/prisma-client/queries/relation-queries#select-specific-relation-fields)
- [Select specific relation fields](/orm/prisma-client/queries/relation-queries#select-specific-fields-of-included-relations)

## Relation count

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -245,9 +245,9 @@ Here's a visual representation of how a nested create operation can write to sev

![](/img/orm/nested-create.png)

### Select specific relation fields
### Select specific fields of included relations

You can use a nested `select` to choose a subset of relation fields to return. For example, the following query returns the user's `name` and the `title` of each related post:
You can use a nested `select` to choose a subset of fields of relations to return. For example, the following query returns the user's `name` and the `title` of each related post:

<CodeWithResult outputResultText="query">
<cmd>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,13 +24,13 @@ This guide demonstrates how to deploy an application to Deno Deploy in conjuncti
- a free [Deno Deploy](https://deno.com/deploy) account
- a PostgreSQL database
- Node.js & npm installed
- Deno v1.29.4 or later installed. [Learn more](https://deno.land/manual/getting_started/installation).
- Deno v1.29.4 or later installed. [Learn more](https://docs.deno.com/runtime/manual/#install-deno).
- (Recommended) Latest version of Prisma ORM.
- (Recommended) Deno extension for VS Code. [Learn more](https://deno.land/manual/getting_started/setup_your_environment#visual-studio-code).
- (Recommended) Deno extension for VS Code. [Learn more](https://docs.deno.com/runtime/manual/references/vscode_deno/).

## 1. Set up your application

To start, you create a directory for your project, and then use `deno run` to initialize your application with `prisma init` as an [npm package with npm specifiers](https://deno.land/manual/node/npm_specifiers).
To start, you create a directory for your project, and then use `deno run` to initialize your application with `prisma init` as an [npm package with npm specifiers](https://docs.deno.com/runtime/manual/node/npm_specifiers/).

To set up your application:

Expand Down Expand Up @@ -149,7 +149,7 @@ serve(handler)

**VS Code error: `An import path cannot end with a '.ts' extension`**<br /><br />

If you use VS Code and see the error `An import path cannot end with a '.ts' extension` for the `import` statements at the beginning of `index.ts`, you need to install the [Deno extension for VS Code](https://deno.land/manual/getting_started/setup_your_environment#visual-studio-code), select **View** > **Command Palette** and run the command **Deno: Initialize Workspace Configuration**. This tells VS Code that the TypeScript files in the current project need to run with Deno, which then triggers the correct validations.
If you use VS Code and see the error `An import path cannot end with a '.ts' extension` for the `import` statements at the beginning of `index.ts`, you need to install the [Deno extension for VS Code](https://docs.deno.com/runtime/manual/references/vscode_deno/), select **View** > **Command Palette** and run the command **Deno: Initialize Workspace Configuration**. This tells VS Code that the TypeScript files in the current project need to run with Deno, which then triggers the correct validations.

</Admonition>

Expand Down
2 changes: 0 additions & 2 deletions src/theme/Footer/Links/MultiColumn/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -32,8 +32,6 @@ function Column({ column }: { column: ColumnType }) {
(item, i) => item?.customProps?.dropdown === "legal"
);

console.log(column)

return (
<div className={clsx(styles.col, "col footer__col", column.title === "socials" && styles.socialColWrapper)}>
{column.title !== "socials" && <div className="footer__title">{column.title}</div>}
Expand Down
Binary file modified static/img/orm/nested-create.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.

0 comments on commit 28942a1

Please sign in to comment.