Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

collectionFetchRelated not working per the guide instructions #207

Closed
nghamilton opened this issue Jul 2, 2020 · 1 comment · Fixed by #440
Closed

collectionFetchRelated not working per the guide instructions #207

nghamilton opened this issue Jul 2, 2020 · 1 comment · Fixed by #440

Comments

@nghamilton
Copy link
Contributor

Following the instructions in the guide, posts :: [Include "comments" Post] <- query @Post |> fetch >>= collectionFetchRelated #comments fails to compile: Couldn't match type ‘Id' "comments"’ with ‘QueryBuilder Comment’

Is the filter on the related models incorrectly using the related model's #id instead of the foreign key field?

This was my workaround:
posts <- mapM (fetchRelated #comments) =<< query @Post |> findManyBy #id postId

@nkpart
Copy link

nkpart commented Aug 25, 2020

I think the problem is the targetForeignKey line. That requires that the parent model (second argument to collectionFetchRelated) being targeted is a Post' (Id' "comments"), while the result of the first fetch is Post' (QueryBuilder Comment).

FYI This is still a problem today on master

mpscholten added a commit that referenced this issue Oct 2, 2020
Currently collectionFetchRelated only worked when the referenced field was a foreign key. Now this also works for query builders.

This fixes #207
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants