-
I've been using Flop for a few weeks, but I haven't figured out how to apply multiple filters for an %{
filters: [
%{
field: :owner_id,
op: :==,
value: user_id
},
%{
field: :visibility,
op: :==,
value: :public
}
]
} I've switched to using an |
Beta Was this translation helpful? Give feedback.
Replies: 2 comments 2 replies
-
Hi @type1fool, Flop does not support combining filters with |
Beta Was this translation helpful? Give feedback.
-
First off, just want to say I really like Flop, and have been using it for many things over the past few months. I forked this repo, and implemented a very basic support for OR support. There are gaps in what this approach can accomplish. It only allows one level of nesting, so it's not going to be a silver bullet, but meets all my needs I've run across so far. My use case is "only retrieve rows where the current time is between the valid_start and valid_end timestamps. If valid_start or valid_end are null, treat them as an infinite range.
This format works fine with the current changeset implementation, and I assume would work fine with URL query parameters, and be pretty straightforward to generate HTML forms with it.
The implementation groups the filters by the integer provided via the 'or' attribute on Filter, then creates a dynamic that 'ors' all the filters in that group, in the order defined. Then it will 'and' each group together. Finally, it applies all remaining filters as normal. Right now the gap that I'll need to revise is that it groups all the non or'd filters together and applies them at the end. The fields should be applied in the defined order to take advantage of short circuiting if the underlying DB is implemented to do so. I created a PR with my work so far if anyone would like to see my implementation, or thinks it would be helpful in moving towards Flop supporting ORs. This is just a rough draft I whipped up in an hour, so I'm not super invested in seeing this merged in or anything, just thought it may be helpful. |
Beta Was this translation helpful? Give feedback.
Hi @type1fool, Flop does not support combining filters with
or
at the moment. There was a bit of discussion about this previously: #219