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

Swift Model Codegen for Unidirectional Has-Many AssociatedFields Missing Index fields #539

Open
lawmicha opened this issue Feb 3, 2023 · 0 comments · May be fixed by #542
Open

Swift Model Codegen for Unidirectional Has-Many AssociatedFields Missing Index fields #539

lawmicha opened this issue Feb 3, 2023 · 0 comments · May be fixed by #542
Labels
bug Something isn't working p2

Comments

@lawmicha
Copy link
Member

lawmicha commented Feb 3, 2023

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[].

@lawmicha lawmicha changed the title Swift Model Codegen for Unidirectional Has-Many AssociatedFields Missing Index Swift Model Codegen for Unidirectional Has-Many AssociatedFields Missing Index fields Feb 3, 2023
@alharris-at alharris-at added bug Something isn't working p2 labels Mar 21, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working p2
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants