aws-amplify / amplify-codegen

Amplify Codegen is a JavaScript toolkit library for frontend and mobile developers building Amplify applications.
Apache License 2.0
59 stars 59 forks source link

feat: use a different associated field for references on native #818

Closed dpilch closed 5 months ago

dpilch commented 5 months ago

Description of changes

Example:

type Primary @model {                                                                                                                
  tenantId: ID! @primaryKey(sortKeyFields: ["instanceId", "recordId"])                                                               
  instanceId: ID!                                                                                                                    
  recordId: ID!                                                                                                                      
  content: String                                                                                                                    
  related: [Related!] @hasMany(references: ["primaryTenantId", "primaryInstanceId", "primaryRecordId"])                              
}                                                                                                                                    

type Related @model {                                                                                                                
  content: String                                                                                                                    
  primaryTenantId: ID!                                                                                                               
  primaryInstanceId: ID!                                                                                                             
  primaryRecordId: ID!                                                                                                               
  primary: Primary @belongsTo(references: ["primaryTenantId", "primaryInstanceId", "primaryRecordId"])                               
}  

The .hasMany on the generated model for native platforms will use associatedWith: primary instead of associatedWith: ["primaryTenantId", "primaryInstanceId", "primaryRecordId"]. This is how composite primary keys work for native currently.

Codegen Paramaters Changed or Added

N/A

Issue #, if available

N/A

Description of how you validated changes

Checklist

By submitting this pull request, I confirm that my contribution is made under the terms of the Apache 2.0 license.