IHP - 如何使用多个collectionFetchRelated?

IHP - How to use multiple collectionFetchRelated?

我有以下评论架构:

Table: Comments
Columns: id, post_id, body, user_id, created_at

我想获取其各自 post 和用户的评论。

对一列使用 collectionFetchRelated 很简单:

comments <- query @Comment 
  |> fetch
  >>= collectionFetchRelated #postId

它可以很容易地被调用,

Include "postId" Comment

但是如何使用它并调用多个列?

你应该可以做到这一点:

comments :: [Include' ["postId", "userId"] Comment] <- query @Comment 
  |> fetch
  >>= collectionFetchRelated #postId
  >>= collectionFetchRelated #userId

Include' ["postId", "userId"] Comment 类型只是 Include "userId" (Include "postId" (Comment))

的 shorthand