How do I query for a list where one of their relat...
# orm-help
t
How do I query for a list where one of their relations is null? It looks like I am unable to correctly query for when a relation is
null
. I want it to return a list of nodes
where
the relationship is
null
. This worked fine in graphcool, but now it doesn’t seem to be the way that you need to do it in Prisma. Here’s my query:
Copy code
query getCompanyAndFees($companyId: ID!) {
	Company: company(
		where: {
			id: $companyId
		}
	) {
		id
		fees(
			where: {
				isEnrollmentFee: true
				tuitionServiceFeeForCompany: null
			}, 
			orderBy: name_ASC
		) {
			id
			name
			tuitionServiceFeeForCompany {
				id
			}
		}
	}
}
This query gives me back the following payload:
Copy code
{
  "data": {
    "Company": {
      "id": "cjac65ek0127b0",
      "fees": []
    }
  }
}
If I comment out this condition in the where clause:
tuitionServiceFeeForCompany: null
You can see I get back several fees where
tuitionServiceFeeForCompany
is
null
Copy code
{
  "data": {
    "Company": {
      "id": "cjac65ek0127b0",
      "fees": [
        {
          "id": "cjaz34ym31hdi0,
          "name": "53 Books",
          "tuitionServiceFeeForCompany": null
        },
        {
          "id": "cjaz37nm71he7",
          "name": "CD & Flash Cards",
          "tuitionServiceFeeForCompany": null
        }
      ]
    }
  }
}
It should be getting back that last result without commenting out the
tuitionServiceFeeForCompany: null
I just found out that the reason this was happening was because the relation was using the new
1.31
syntax of using an
INLINE
relation. When I switch it back to
TABLE
it returns the expected data. @Harshit would this be considered a bug or expected behavior?
h
@tmoney was this a upgraded server like you upgraded from older syntax to newer syntax?
t
Well we were coming from graphcool, so I guess so?
We just do a graphcool export to a prisma import on prisma 1.34.0
h
Ok, got it. Your underlying database is using a join table for relations, so if you mark them with a strategy that uses a foreign, it will obviously won't work as there is no data in place
t
Right now we have all the relations working through the inline, foreign keys. In this particular case, there are
fees
with no
tuitionServiceFeeForCompany
and there is one
fee
with a
tuitionServiceFeeForCompany
defined. It's not filtering the ones that don't have the relation defined, it's just not returning any data at all.
h
It might be a bug then, please report it with a minimal reproduction
t
Ok, thanks @Harshit! We will do that
t
Oh wow looks like someone else already reported it: https://github.com/prisma/prisma/issues/4784
h
Thanks, I am going over Prisma 1 issues twice per week, will look into this on Monday
t
@Harshit Is the steps to reproduce in this issue good enough? Or should we provide any more info?
h
Reproduction looks detailed, I will ping you on GitHub if I can't repro
t
Perfect! Have a great weekend 🙂