1

I have the following Comments schema:

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

I want to fetch comments with its respective post and user.

Using collectionFetchRelated for one column is simple:

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

And it can be easily called by,

Include "postId" Comment

But how to use it and call for multiple columns?

Varun Rajput
  • 235
  • 1
  • 7

1 Answers1

2

You should be able to do this:

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

The Include' ["postId", "userId"] Comment type is just a shorthand for Include "userId" (Include "postId" (Comment))

Marc Scholten
  • 1,351
  • 3
  • 5