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?
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))