How to build WHERE IN array clause with Ecto?

前端 未结 3 1965
借酒劲吻你
借酒劲吻你 2021-02-01 02:41

How to find posts in given List of ids?

This isn\'t working:

posts = Post |> where(id: [1, 2]) |> Repo.all

Example in Rails:

3条回答
  •  礼貌的吻别
    2021-02-01 03:00

    Accepted answer gives undefined function p/0 to me, so I came to this:

    from(p in Post, where: p.id in [1, 2]) |> Repo.all
    

提交回复
热议问题