-
Notifications
You must be signed in to change notification settings - Fork 63
Open
Labels
Description
In this PR #538 we're populating the associatedFields of a has-many connection. There is one case that doesn't seem to be working as expected. For this schema:
// Uni-directional has-many with CPK on parent, with customized FK
type Post8 @model {
postId: ID! @primaryKey(sortKeyFields:["title"])
title: String!
comments: [Comment8] @hasMany(indexName:"byPost", fields:["postId", "title"])
}
type Comment8 @model {
commentId: ID! @primaryKey(sortKeyFields:["content"])
content: String!
postId: ID @index(name: "byPost", sortKeyFields:["postTitle"]) # customized foreign key for parent primary key
postTitle: String # customized foreign key for parent sort key
}
The output of Post's schema file contains .hasMany(comments)
.hasMany(post.comments, is: .optional, ofType: Comment.self, associatedFields: [Comment.keys.postId])
This output doesn't look accurate
The associatedFields of the comment to the post should be the foreign key fields on the Comment "postId" and "postTitle".
The expected output, to my understanding, should be:
.hasMany(post.comments, is: .optional, ofType: Comment.self, associatedFields: [Comment.keys.postId, Comment.keys.postTitle])
Opening this issue to bring awareness to see if we can collaborate on the solution. The code is getting pretty complicated to debug. My initial hunch is that somewhere in getConnectedFieldsForHasMany is not picking up "postTitle" and returning it in the CodeGenField[].