sezaru
Compare nullable fields in filters
I have this filter in my action:
|> Ash.Query.filter(organization_id == ^actor.organization_id)
The issue with it is that organization_id can be null, so when that happen, I will get this warning:
warning: Comparing values with `nil` will always return `false`. Use `is_nil/1` instead. In: `organization_id == nil`
(core 1.95.1) lib/core/marketplace/markets/property/actions/retrades_required.ex:12: Core.Marketplace.Markets.Property.Actions.RetradesRequired.run/2
(ash 3.4.18) lib/ash/actions/action.ex:129: Ash.Actions.Action.run/3
(ash 3.4.18) lib/ash.ex:1376: Ash.run_action/2
(ash 3.4.18) lib/ash.ex:1347: Ash.run_action!/2
(core 1.95.1) lib/core_web/live/admin/dashboard_live.ex:131: CoreWeb.Admin.DashboardLive.do_load_card_data/2
(phoenix_live_view 0.20.17) lib/phoenix_live_view/async.ex:220: Phoenix.LiveView.Async.do_async/5
(elixir 1.17.2) lib/task/supervised.ex:101: Task.Supervised.invoke_mfa/2
How can I rewrite that so I will stop getting this warning?
Marked As Solved
zachdaniel
Creator of Ash
How about something like this?
|> then(fn query ->
if is_nil(actor.organization_id) do
Ash.Query.filter(query, is_nil(organization_id))
else
Ash.Query.filter(query, organization_id == ^actor.organization_id)
end
end)
0
Popular in Questions
Hi,
I need to transform a list of numbers into a map where the keys are the indexes and the values are the original values of the list. ...
New
Hello, how can I check the Phoenix version ?
Thanks !
New
There are pre-rolled solutions for other frameworks that do work. However, Phoenix does not seem to have these. Have people had good expe...
New
I want to highlight html closing tags when i click a html tag. That works in .html files but doesnt work for html.eex templates. How can...
New
About me? ( if you have nothing better to do than reading about some random guy in the internet :stuck_out_tongue: )
Hello all, this is ...
New
I am VERY much an elixir newbie. I have taken one elixir course and one phoenix course on Udemy. During that course, I saw the instructor...
New
Erlang/OTP 25 [erts-13.2.2] [source] [64-bit] [smp:8:8] [ds:8:8:10] [async-threads:1]
15:22:35.803 [error] gen_event {lager_file_backend...
New
Other popular topics
Hi,
I am new to Elixir. I am trying to use the DateTime component to insert a date into MySQL however the there seems to be no way to fo...
New
I have seen a lot of code which picks the first element from a list using Enum.at(0) instead of List.first. Is there a reason why people ...
New
Original source of discussion: This topic on the Pragmatic Programmers’ Functional Web Development with Elixir, OTP, and Phoenix forum.
...
New
When I run the Plug and I recompile I wind up having to use Ctrl C to quit iex and start again. Witht the help of rlwrap I can use the cu...
New
Hello again - after a longish gap I’ve decided I really must dig into Elixir and see what’s been happening here - so I have a few questio...
New
I have a phoenix application from which a user can download multiple(5-6) files of size 1MB. I couldn’t find anything related to sending ...
New
Categories:
Sub Categories:
Forums
Popular Tags
- #ecto
- #liveview
- #troubleshooting
- #learning-elixir
- #deployment
- #library
- #erlang
- #testing
- #genserver
- #mix
- #absinthe
- #remote-other
- #otp
- #plug
- #how-to-question
- #macros
- #postgres
- #channels
- #elixirconf
- #exunit
- #discussion
- #code-sync
- #javascript
- #podcasts
- #onsite
- #dialyzer
- #docker
- #authentication
- #umbrella
- #full-time-contract
- #podcasts-by-brainlid
- #ecto-query
- #elixir-ls
- #phoenix_html
- #iex
- #blog-post
- #graphql
- #genstage
- #ai
- #websockets
- #supervisor
- #elixirconf-us
- #advent-of-code
- #distillery
- #processes
- #api
- #forms
- #metaprogramming
- #security
- #hex









