Ecto how to fetch records from list with one query

I have list of dates. What i want fecth all records with one query instead of 7 query. Is that possible ?

dates = ["2018-02-26", "2018-02-27", "2018-02-28", "2018-03-01", "2018-03-02",
 "2018-03-03", "2018-03-04"]

  def list_bookings( date) do
    Booking
    |> where([t],  t.date == ^date)
    |> Repo.all
  end

You’re probably looking for or_where in queries.

1 Like

Not tested… but You can use in to test membership.

def list_bookings(dates) do
  Booking 
  |> where([t], t.date in ^dates) 
  |> Repo.all
end
2 Likes