-
Hey! I'm using Flop for the first time, and I'm having a question. I'm trying to filter a field of type
I'm using the But now I'm unsure how to proceed. I've made a custom filter that uses Any suggestions are welcome! I'm enjoying the library. But since I'm new to it, maybe my expectations are wrong... |
Beta Was this translation helpful? Give feedback.
Replies: 2 comments 1 reply
-
This issue is probably related: #286 |
Beta Was this translation helpful? Give feedback.
-
You found the right issue. Right now, Flop relies on Ecto when it comes to filter values. Until 0.19, there was no way to tell Flop the Ecto type for join fields. Now that that is in place, and after adding the def list_pets(params \\ %{}) do
Flop.validate_and_run(Pet, params, for: Pet)
rescue
Ecto.Query.CastError -> {:ok, {[], %Flop.Meta{}}}
end You'll need to set the meta fields yourself in this case, though. |
Beta Was this translation helpful? Give feedback.
You found the right issue. Right now, Flop relies on Ecto when it comes to filter values. Until 0.19, there was no way to tell Flop the Ecto type for join fields. Now that that is in place, and after adding the
ecto_type
option to alias fields as well, we have all the necessary information to validate filter values before they are passed to Ecto. Until that has been implemented, I see two workarounds. One would be the solution with custom fields you described, which admittedly is a bit cumbersome, and the other would be to catch the CastError:You'l…