More Ecto questions! More madness!
The context: there’s a list of books that I want to filter with a dropdown…
The dropdown: looks something like (gt stands for greater than, lt stands for land tanks)…
def word_count_options do [ "0 - 5k": [gt: 0, lt: 5000], "5k - 30k": [gt: 5000, lt: 30000], "30k - 100k": [gt: 30000, lt: 100000], "100k - 200k": [gt: 100000, lt: 200000], "200k+": [gt: 200000, lt: 1000000000] ] end
The current code: almost works, but I would like to make this into ONE where clause with OR between the word count checks (so I can compose other queries that use where with this query without mucking up my intended filter logic)…
Enum.reduce(filters, query, fn filter, query ->
options = Fic.word_count_options[String.to_existing_atom filter]
from f in query, or_where: f.word_count > ^options[:gt] and f.word_count < ^options[:lt]
end)
What’s the best path forward here? The “dynamic” keyword kinda seem like what I need, but I feel there’s a more straightforward way to handle this pattern…