Hi, I’ve got a question about inline relationships...
# prisma1-community
m
Hi, I’ve got a question about inline relationships. As the foreign key for this relationship is stored inline in the same table as the root basic fields, is there any way to resolve the foreign key value as a root field? At the moment I’m having to run extra queries to resolve this field which is leading to n+1 query problems
r
@Moray Macdonald 👋 Could you provide an example if possible?
m
Of course, just a sec
Copy code
type Tenant {
  id: ID! @id
}

type User {
  id: ID! @id
  owner: Tenant! @relation(link: INLINE)
}
so if I wanted the ID of the
Tenant
that the
User
is linked to, I need to do this:
Copy code
owner: (root, args, context) => await context.db.user({ id: root.id }).owner().id();
Or in GraphQL
Copy code
user(id: $id){
  owner {
    id
  }
}
As this inline Tenant-User relationship will get translated into this SQL
Copy code
CREATE TABLE User (id CHAR(25), owner CHAR(25));
Can I get the value of the owner column on the root
User
without having to resolve it through a second DB query?
As the data is right there, next to all the other root fields!
r
I don’t think that is possible though unless you use a raw query.
👍 1
m
Ah OK, thanks for your help
🙌 1