Using date comparison in where when building Ecto associations

Hi!

I’m trying to build has_one relation based on where conditions.

I know that I can use where: ... with has_one/has_many but it seems like it doesn’t support comparison other than equality. In my case, I need to compare dates with < and >.

Any ideas on how can I handle it?

Here is the example code (the three dots is the place where I’m confused):

defmodule A do
  has_one :b, where: [valid_from: ..., valid_until: ...]
end

Heh, use cases like this are part of why Ecto resisted even having where on has_one for a long time. You’d handle this via A |> B.for_a where def for_a(a) was a completely ordinary function that just built up the query.