Skip to content

Commit 6ab7daa

Browse files
Rafał Dzięgielewskigitbook-bot
Rafał Dzięgielewski
authored andcommitted
GITBOOK-113: change request with no subject merged in GitBook
1 parent 75b4888 commit 6ab7daa

File tree

1 file changed

+65
-0
lines changed

1 file changed

+65
-0
lines changed

basics/features/relations.md

+65
Original file line numberDiff line numberDiff line change
@@ -69,6 +69,10 @@ The two features will be explained in more detail in the later parts of this gui
6969

7070
The usage guide will be based on sample database tables which can be represented by the following interfaces:
7171

72+
73+
74+
{% tabs %}
75+
{% tab title="Generic" %}
7276
```typescript
7377
interface IOrganization {
7478
id: number;
@@ -109,6 +113,63 @@ interface IOffice {
109113
Team belongs to multiple Persons through TeamMember
110114
*/
111115
```
116+
{% endtab %}
117+
118+
{% tab title="Prisma Schema" %}
119+
```prisma
120+
generator client {
121+
provider = "prisma-client-js"
122+
}
123+
124+
datasource db {
125+
provider = "postgresql"
126+
url = env("DATABASE_URL")
127+
}
128+
129+
model Organization {
130+
id Int @id @default(autoincrement())
131+
name String
132+
persons Person[]
133+
134+
@@map("organizations")
135+
}
136+
137+
model Person {
138+
id Int @id @default(autoincrement())
139+
firstName String @map("first_name")
140+
lastName String @map("last_name")
141+
email String
142+
phone String
143+
dateOfBirth DateTime? @map("date_of_birth")
144+
isActive Boolean
145+
organization Organization @relation(fields: [organizationId], references: [id])
146+
organizationId Int @map("organization_id")
147+
148+
teams TeamMember[]
149+
150+
@@map("persons")
151+
}
152+
153+
model Team {
154+
id Int @id @default(autoincrement())
155+
name String
156+
members TeamMember[]
157+
158+
@@map("teams")
159+
}
160+
161+
model TeamMember {
162+
id Int @id @default(autoincrement())
163+
personId Int @map("person_id")
164+
person Person @relation(fields: [personId], references: [id])
165+
teamId Int @map("team_id")
166+
team Team @relation(fields: [teamId], references: [id])
167+
168+
@@map("team_members")
169+
}
170+
```
171+
{% endtab %}
172+
{% endtabs %}
112173

113174
`@adminjs/relations` is adapter-agnostic which means you can use it regardless of the database adapter you had installed. Nevertheless, some ORMs automatically generate and manage junction tables for you without you having to actually create entities for them in your codebase. This will not work with AdminJS and you will have to create actual entities for junction tables and register them as AdminJS resources since AdminJS uses them to find your `M:N` records.
114175

@@ -176,6 +237,10 @@ type RelationsFeatureConfig = {
176237

177238
### One-To-Many
178239

240+
{% hint style="warning" %}
241+
If using Prisma, configure the `joinKey` and `inverseJoinKey` options by providing the relation names instead of foreign keys, for example: `organization` instead of `organizationId`
242+
{% endhint %}
243+
179244
According to the database structure described above as well as the presented configuration options of `owningRelationSettingsFeature`, this is how you can add this feature to `Organization` resource which can have many `Persons` and `Offices`
180245

181246
{% code title="organization.resource.ts" %}

0 commit comments

Comments
 (0)