3

In my application I need to be able to write a query that takes a list of IDs and returns a list of each of those records.

From what I can tell from the yesod persistent page I could do something like

selectList (UserId ==. 1 ||. UserId ==. 2 ||. UserId ==. 3) []

Which I believe would return a list containing user 1, 2 and 3 but I can't work out how I would write this query when I don't know the list or how long it will be at compile time.

How would I go about selecting a list of records using a list of IDs in Haskell persistent.

4

1 回答 1

3

Persistent 有几个用于创建查询的组合器,您正在寻找的是(<-.) :: PersistField typ => EntityField v typ -> [typ] -> Filter v.

然后您的查询可以简化为

selectList [UserId <-. [1..3]] []
于 2018-01-06T15:23:35.943 回答