lardcanoe

lardcanoe

Ash resource filtering embedded map with user input

I am trying to parse a user generated filter that will apply to jsonb field (that is just a map, not an embedded resource).

The field is data, and if I include it in the statement sent to parse_input I get an Ash.Error.Query.NoSuchFilterPredicate error.

If I exclude that field, and instead manually apply it, |> Ash.Query.filter(data[:size] == ^"Big") then things works.

Is there a syntax to allow passing fields of a map into the parse function? If not, how can I pass it to Ash.Query.filter? To make it slightly more complicated, I would also like to be able to filter on the data field when it is on a reference as well. e.g. `%{person: %{data: %{size: “Big”}}}

    statement = %{
      person: %{parent: %{name: "Daniels"}},
      data: %{size: "Big"}
    }

    # This will blow up with the above
    {:ok, filter} = Ash.Filter.parse_input(resource, statement)

    # If I remove "data" and instead do it manually, then this works:
    resource
    |> Ash.Query.for_read(read_action, %{}, actor: actor, tenant: tenant)
    |> Ash.Query.filter_input(filter)
    |> Ash.Query.filter(data[:size] == ^"King")

Filtering on embedded resource? - #6 by zachdaniel was where I saw the Ash.Query.filter approach on arbitrary fields of a jsonb attribute; I just couldn’t figure out how to pass my user generated filter since that is a macro.

Thank you!

Marked As Solved

zachdaniel

zachdaniel

Creator of Ash

So, I made that change and realized that it just kind of shuffles the problem around, because if you have an attribute called at_path it would be problematic…but actually I think it’s fine. The reason its fine is that at_path expects a list, and if you need to match on it you can say at_path: %{eq: ["foo"]}, so there is an escape hatch (albeit a bit of a convoluted one)

Also Liked

zachdaniel

zachdaniel

Creator of Ash

Alright, I’ve pushed this change to main (and removed the previous change I added)

Where Next?

Popular in Questions Top

nobody
How to bind a phoenix app to a specific ip address? could not find anything about that, nowhere, unfortunately, but for me this is quite...
New
JorisKok
I have a server on AWS, and was running a load test using artillery. When looking at the Phoenix dashboard I see the Ports going to 100% ...
New
hariharasudhan94
lets say i have a sample like a = 20; b = 10; if (a > b) do {:ok, "a"} end if (a < b) do {:ok, b} end if (a == b) do {:ok, "equa...
New
dokuzbir
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
itssasanka
Hi all, Trying to get some more clarity over utc_datetime and naive_datetime for Ecto: The documentation above suggests that while ...
New
Qqwy
Original source of discussion: This topic on the Pragmatic Programmers’ Functional Web Development with Elixir, OTP, and Phoenix forum. ...
New
ashish173
I am using Ecto timestamps with postgres, I can see the timestamps() use the :naive_dateime but for my use case I wanted to store the ti...
New
dotdotdotPaul
Okay, I’m having a heck of a time trying to figure out how to best handle the validation of belongs_to associations in Ecto. I’m sure I’...
New
joaquinalcerro
Hi there, I am working with Ecto-Postgresql and I need to call all of the records from a specific table but the table has 40,000 records...
New
openscript
Hello! Sorry for this astonishing simple question, but I’m really stuck. I try to set up the intellij-elixir plugin, but I don’t know ho...
New

Other popular topics Top

sen
Hi All, I set a environment variables in dev.exs , like below code. when i start server, how can i set the ${enable} value? thanks. d...
New
marius95
Hello everyone, I try to use an Javascript Event Handler in my root.html.leex file. Therefore I created a function in the app.js file: ...
New
malloryerik
Hi, this is for people who, like me, have had some friction using .html.heex templates in VSCode. The solution seems to be, in a hyphena...
New
New
sorentwo
Hello! tl;dr Announcing Oban, an Ecto based job processing library with a focus on reliability and historical observability. After spen...
985 42920 311
New
electic
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
Fl4m3Ph03n1x
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
jay1
Why is it that the mnesia database isn’t the most preferred database for use in Elixir/Phoenix?
New
sergio_101
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
vonH
In asking this question I am more interested about the expressiveness of the language itself and less concerned about the availability of...
New

We're in Beta

About us Mission Statement