woylie/flop

Concatenated value comparison for compound fields

Closed this issue · 4 comments

  • Implement the remaining operators for compound fields: :==, :!=, :<=, :<, :>=, :>, :in
aej commented

Hi @woylie 👋 Thanks for making such a great library.

I have a need for filtering on the concatenated values of compound fields. I was wondering if this issue was still planned or if there is a workaround I can use instead.

Hi @aej,

I closed it because I didn't think anybody would need it, but I can re-open the issue, and I'm certainly open to a PR. A workaround in the current release version would be a lateral join on a subquery (https://hexdocs.pm/flop/Flop.Schema.html#module-filtering-by-calculated-values). There's a new feature called custom fields on the main branch that you could also use for this (https://github.com/woylie/flop/blob/main/lib/flop/schema.ex#L355).

The problem though is that Ecto does not have a concat macro, and we can't just use a fragment, since the syntax differs depending on the database.

aej commented

I've managed to solve the problem using a lateral join and a subquery (with a fragment using concat) as you suggest. For now that works perfectly fine for me.

I'll give the custom fields a go too! I have a use-case which fits that really well.