I have three models Organisation, Application and ApiKey. An organisation can have many applications, an application can have many api-keys. When looking for an api-key I want to include the id of the application AND the id of the organisation. Since the api-key is owned by an application and an application is owned by the organisation I have to work with an include on the application field which leads to the organisation_id being nested in the application object.
Is it possible, without adding an extra relationship between Organisation and ApiKey, to get the organisation_id in the main object?
My current object:
{
id: 'd61536c3-2a68-4d98-b319-9efaffc020bf',
code: '5df07f13-86d7-4d67-b56e-6c9668dd6bca',
is_active: true,
application_id: '68e7e353-3def-4b94-b3f1-9735b45a1ebf',
application: {
id: '68e7e353-3def-4b94-b3f1-9735b45a1ebf',
name: 'Test app',
url: null,
organisation_id: '06531a5d-b9db-43a9-ac98-a9b61f83eb98',
}
}
What I would like:
{
id: 'd61536c3-2a68-4d98-b319-9efaffc020bf',
code: '5df07f13-86d7-4d67-b56e-6c9668dd6bca',
is_active: true,
application_id: '68e7e353-3def-4b94-b3f1-9735b45a1ebf',
organisation_id: '06531a5d-b9db-43a9-ac98-a9b61f83eb98'
}
prisma.schema
model Organisation {
id String @id @default(uuid())
name String @unique
applications Application[]
@@map("organisations")
}
model Application {
id String @id @default(uuid())
name String
organisation Organisation @relation(fields: [organisation_id], references: [id])
organisation_id String
api_keys ApiKey[]
@@map("applications")
}
model ApiKey {
id String @id @default(uuid())
code String @unique
is_active Boolean @default(true)
application Application @relation(fields: [application_id], references: [id])
application_id String
@@map("api_keys")
}