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

Custom primary key @primaryKey doesn’t work with @auth #753

Open
2 of 14 tasks
stephenjen opened this issue Nov 3, 2023 · 2 comments
Open
2 of 14 tasks

Custom primary key @primaryKey doesn’t work with @auth #753

stephenjen opened this issue Nov 3, 2023 · 2 comments
Labels
bug Something isn't working transferred Issue has been transferred from another Amplify repository

Comments

@stephenjen
Copy link

stephenjen commented Nov 3, 2023

Description

I have two parent / child tables, and the parent table has custom primary key:

type Book @model @auth(rules: [{ allow: private, ownerField: "pOwner" }]) {
  id: ID! @primaryKey(sortKeyFields: ["title", "description"])
  title: String!
  description: String!
  writers: [Writer] @hasMany(indexName: "byBook", fields: ["id"])
  pOwner: String!
}

type Writer @model {
  id: ID!
  fname: String!
  lname: String!
  bookID: ID! @index(name: "byBook", sortKeyFields: ["id"])
  book: Book! @belongsTo(fields: ["bookID"])
  pOwner: String!
}

When I add the same @auth to the child, I get the following error on attempt to generate the model with 'amplify codegen models':

InvalidDirectiveError: Invalid @belongsTo on Writer:book. Provided fields do not match the size of primary key(s) for Book

Below are the models that cause this error:

type Book @model @auth(rules: [{ allow: private, ownerField: "pOwner" }]) {
  id: ID! @primaryKey(sortKeyFields: ["title", "description"])
  title: String!
  description: String!
  writers: [Writer] @hasMany(indexName: "byBook", fields: ["id"])
  pOwner: String!
}

type Writer @model @auth(rules: [{ allow: private, ownerField: "pOwner" }]) {
  id: ID!
  fname: String!
  lname: String!
  bookID: ID! @index(name: "byBook", sortKeyFields: ["id"])
  book: Book! @belongsTo(fields: ["bookID"])
  pOwner: String!
}

Categories

  • Analytics
  • API (REST)
  • API (GraphQL)
  • Auth
  • Authenticator
  • DataStore
  • Notifications (Push)
  • Storage

Steps to Reproduce

No response

Screenshots

No response

Platforms

  • iOS
  • Android
  • Web
  • macOS
  • Windows
  • Linux

Flutter Version

3.13.5

Amplify Flutter Version

1.5.0

Deployment Method

Amplify CLI

Schema

No response

@khatruong2009 khatruong2009 added DataStore pending-triage Issues that need further discussion to determine labels Nov 3, 2023
@Jordan-Nelson
Copy link
Contributor

Hello @stephenjen - I was able to reproduce this issue. I am going to transfer this issue to our code gen repo.

@Jordan-Nelson Jordan-Nelson transferred this issue from aws-amplify/amplify-flutter Nov 9, 2023
@Jordan-Nelson Jordan-Nelson added the transferred Issue has been transferred from another Amplify repository label Nov 9, 2023
@stephenjen
Copy link
Author

@Jordan-Nelson Thanks for pushing this forward

@phani-srikar phani-srikar added bug Something isn't working and removed pending-triage Issues that need further discussion to determine labels Dec 11, 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 transferred Issue has been transferred from another Amplify repository
Projects
None yet
Development

No branches or pull requests

4 participants