如何在给定的 ID 列表中查找帖子?
这不起作用:
posts = Post |> where(id: [1, 2]) |> Repo.all
Rails 中的示例:
Post.where({ id: [1, 2]})
# SELECT * FROM posts WHERE id IN (1, 2)
最佳答案
以下应该工作:
posts = Post |> where([p], p.id in [1, 2]) |> Repo.all
关于elixir - 如何使用 Ecto 构建 WHERE IN 数组子句?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/36814260/