Skip to content

Commit

Permalink
fix(amplify-codegen): swift - add has-many targetNames for CPK use case
Browse files Browse the repository at this point in the history
  • Loading branch information
lawmicha committed Feb 2, 2023
1 parent cf7f167 commit c4234fc
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@ extension Post {
model.fields(
.field(post.id, is: .required, ofType: .string),
.field(post.title, is: .required, ofType: .string),
.hasMany(post.comments, is: .optional, ofType: Comment.self, associatedWith: Comment.keys.postCommentsId),
.hasMany(post.comments, is: .optional, ofType: Comment.self, associatedWith: Comment.keys.postCommentsId, targetNames: [\\"postCommentsId\\",\\"postCommentsTitle\\"]),
.field(post.createdAt, is: .optional, isReadOnly: true, ofType: .dateTime),
.field(post.updatedAt, is: .optional, isReadOnly: true, ofType: .dateTime)
)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -615,9 +615,12 @@ export class AppSyncSwiftVisitor<
// connected field
if (connectionInfo) {
if (connectionInfo.kind === CodeGenConnectionType.HAS_MANY) {
const targetNameAttrStr = this.isCustomPKEnabled()
? `, targetNames: [${connectionInfo.associatedWithFields.map(target => `"${this.getFieldName(target)}"`).join(',')}]`
: '';
return `.hasMany(${name}, is: ${isRequired}, ofType: ${typeName}, associatedWith: ${this.getModelName(
connectionInfo.connectedModel,
)}.keys.${this.getFieldName(connectionInfo.associatedWith)})`;
)}.keys.${this.getFieldName(connectionInfo.associatedWith)}${targetNameAttrStr})`;
}
if (connectionInfo.kind === CodeGenConnectionType.HAS_ONE) {
const targetNameAttrStr = this.isCustomPKEnabled()
Expand Down

0 comments on commit c4234fc

Please sign in to comment.