Question : elixir ecto pluck ids
Answered by : nguyen-quang-huy
ids = [123, 4, 1, 3, 2, 456]
posts = from(p in Post, where: p.id in ^ids, select: {p.id, p}) |> Repo.all |> Map.new
posts = for id <- ids, posts[id], do: posts[id]
posts |> Enum.map(&(&1.id)) |> IO.inspect
Source : | Last Update : Tue, 21 Jun 22