Hello everybody, wanted to ask if it’s the proper ...
# orm-help
j
Hello everybody, wanted to ask if it’s the proper way to get the relation fields of
someModelName2
?
Copy code
prisma.someModelName0.findUnique(...).someModelName1().someModelName2({
  include: {
    someModelName3: {
      select: {
        someFieldName: true
      }
    }
  }
})
I didn’t found any info about this in the Fluent Api docs. I mean the usage of
select
and
include
here. It seems that it’s working, but wanted to ask anyway. Thank you.
r
Yes you can either use `select`/`include` or the fluent API. If you require deeply nested relations then `select`/`include` is needed. Fluent API is only for a single level relation.
j
Thanks for the reply. I mean can I use select/include with the Fluent API? E.g. I want to get only names of the posts of the user. Is this a right way to do it ?
Copy code
prisma.user.findUnique(...).posts({
  select: { name: true }
})
Or I want to get only names(scalar) of the groups(relation) of the posts(relation) of the user(relation) ?
Copy code
prisma.user.findUnique(...).posts({
  include: {
    groups: {
      select: {
        name: true
      }
    }
  }  
})
r
Yes you can do that.
j
Thank you
🙌 1