I have a simple query using
is_nil/1, but it’s not working and I’m getting the error:
comparison with nil is forbidden as it is unsafe. If you want to check if a value is nil, use is_nil/1 instead
Here’s the query
cohort_chat_query = from c in Chat,
where: c.cohort_id == ^attrs["cohort_id"] and is_nil(c.team_id)
Any help would be great, thanks.
Hi, just a guess, maybe you need parentheses
where: (c.cohort_id == ^attrs["cohort_id"]) and is_nil(c.team_id)
hth, (Merry Xmas!)
Thanks for the guess and holiday wishes!
I just tried that but still not working.
Oddly, this this line works in iex console but not in my dev environment.
Ok, found the solution.
The issue was
attrs["cohort_id"] was nil. I had to change it to
is_nil(c.team_id) part was working fine.