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

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

Merged
merged 8 commits into from
Apr 26, 2024

Conversation

dpilch
Copy link
Member

@dpilch dpilch commented Apr 23, 2024

Description of changes

  • remove respectReferences and enable references for all platforms
  • use the connected field instead of associatedWithFields on native for references

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

  • Unit tests
  • Verify in native e2e tests

Checklist

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

@dpilch dpilch force-pushed the associated-field-native branch from f4c7525 to 52678cc Compare April 23, 2024 23:31
@dpilch dpilch changed the title Associated field native fix: use a different associated field for references on native Apr 23, 2024
@dpilch dpilch changed the base branch from feature/gen2-release to fix-snapshot April 23, 2024 23:34
@dpilch dpilch marked this pull request as ready for review April 25, 2024 13:43
@dpilch dpilch requested a review from a team as a code owner April 25, 2024 13:43
@dpilch dpilch changed the base branch from fix-snapshot to feature/gen2-release April 25, 2024 13:43
@dpilch dpilch force-pushed the associated-field-native branch from 245be17 to b668fd2 Compare April 25, 2024 13:48
Copy link
Member

@palpatim palpatim left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

naming nit, otherwise LGTM

// native uses the connected field instead of associatedWithFields
// when using references associatedWithFields and associatedWithNative are not the same
// getConnectedFieldV2 also ensures there is a matching belongsTo field with references
const associatedWithNativeReferences = getConnectedFieldV2(field, model, otherSide, connectionDirective.name, shouldUseModelNameFieldInHasManyAndBelongsTo)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

naming nit: can we come up with something more descriptive than V2? :) Maybe getConnectedFieldForNativeReferences or something?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks like the getConnectedFieldV2 API was around for a while and used in multiple places. We can maybe refactor this outside of this PR?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I moved the refactor to #822

phani-srikar
phani-srikar previously approved these changes Apr 25, 2024
@dpilch dpilch changed the base branch from feature/gen2-release to main April 25, 2024 20:22
@dpilch dpilch force-pushed the associated-field-native branch from 50cd346 to 14ee319 Compare April 25, 2024 20:27
@dpilch dpilch changed the title fix: use a different associated field for references on native feat: use a different associated field for references on native Apr 25, 2024
@dpilch dpilch enabled auto-merge (squash) April 26, 2024 13:37
@dpilch dpilch merged commit 9a8d048 into main Apr 26, 2024
4 checks passed
@palpatim palpatim deleted the associated-field-native branch April 26, 2024 13:59
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 this pull request may close these issues.

4 participants