@connection directive doesn't create an one-to-many relationship using primary key.
See original GitHub issueDescribe the bug @connection directive doesn’t create an one-to-many relationship using primary key.
To Reproduce
- Create two types (account and book) at schema.
- Account uses @key to declare userId as its simple primary key.
- Book uses @key to declare userId and createdAt as its composite primary key.
- Account uses @connection next to its books field to connect with book type with “userId” as primary key.
- Create an account followed by creating a book using the same userId .
- Query account and its books field shows null.
type account
@model
@key(fields: ["userId"])
) {
userId: String!
books: [book] @connection(fields: ["userId"])
}
type book
@model
@key(fields: ["userId", "createdAt"])
) {
userId: String!
createdAt: String!
title: String
author: String
}
Expected behavior When account is query, it’s books field should show the book created.
Issue Analytics
- State:
- Created 3 years ago
- Comments:6 (2 by maintainers)
Top Results From Across the Web
Amplify GraphQL @connection Directive | Geek Culture
One -to-many connections require an index created with the @key on a connected object. In the schema below, the Comment object schema has...
Read more >Create a one to many relationship using SQL Server
My professor at USC told us this simple rule: when there is one to many relationship, put the key of 'one' side as...
Read more >API (GraphQL) - Data modeling - AWS Amplify Docs
A @hasOne relationship always uses a reference to the primary key of the related model, by default id unless overridden with the @primaryKey...
Read more >Video: Create many-to-many relationships
To complete the many-to-many relationship, create a one-to-many relationship between the primary key field in each table and the matching field in the ......
Read more >Datamodel (MySQL) - Prisma 1.34
"Post" ( "id" varchar(25) NOT NULL, "author" varchar(25), PRIMARY KEY ("id") );. Note that in this case the @relation directive could also be...
Read more >
Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free
Top Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
I just checked. This issue has been resolved sometimes ago (idk by which commit). The documentation also makes a note
If keyName is not provided, then @connection queries the target table’s primary index.
Good work Amplify team!This issue has been automatically locked since there hasn’t been any recent activity after it was closed. Please open a new issue for related bugs.
Looking for a help forum? We recommend joining the Amplify Community Discord server
*-help
channels for those types of questions.