Hi Guys, does anybody know how to make a filter on...
# prisma-whats-new
d
Hi Guys, does anybody know how to make a filter on a joined relation? I’d like to filter a list where the actual filter lookup is in a nested relation, similar to query WHERE statement of MySQL on a joined table? Is this somehow possible at the moment? Thanks!
y
@dohomi Yes, you just need make your filter a nested object as well. such as:
Copy code
allItems(filter: {otherThing: {name: "thing I want"}}) {
  data
}
d
@yergi thanks for your answer.. I tried inside of the playground without success,I would need to nest 2 levels deep:
Copy code
toUsers_every:{client:{agentGroup:{id:"someID"}}}}
but the result is every item..
y
Did you wrap it in the
(filter: )
?
Copy code
toUsers_every(filter: {client: {agentGroup: {id: "someId"}}}) {
  dataYouWantBack
}
d
it seems to work like this:
Copy code
allItems(filter:{toUsers_some:{client:{agentGroup:{id:"someId"}}}}){
I did not repeat the filter: keyword but changed _every => _some.. not sure why though
y
There are special meta variables available when performing the filter function.
When referring to a reference, you can append
_some
,
_none
, or
_every
When referencing a value inside a node, you can use
_lte
,
_not
,
_contains
, etc.
To tell GraphQL the logic you want to use on that reference / value when filtering.
@nilan or someone else will need to explain the difference between
_some
and
_every
. I’m not clear on that.
n
Hey @dohomi and @yergi 🙂
allItems(filer: {toUsers_some: { name: "Nilan"} })
will only match items, where at least some users are named Nilan
allItems(filer: {toUsers_every: { name: "Nilan"} })
will only match items, where all users are named Nilan
allItems(filer: {toUsers_none: { name: "Nilan"} })
will only match items, where no user is named Nilan
d
@yergi @nilan so this is my query:
Copy code
filter:{OR:[
  {toUsers_some:{client:{agentGroup:{id:"someId"}}}},
{fromUsers_some:{client:{agentGroup:{id:"someId"}}}}]})
==> WORKS :-)
n
👍
d
thanks for the heads up you both! cheers