question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

One to one connections

See original GitHub issue

I’m getting the following error when I attempt to compile my schema:

InvalidDirectiveError: Connection is to a single object but the keyName <key-name> was provided which does not reference the default table.

Is it possible to define a one-to-one relationship with a keyName argument?

Which Category is your question related to? GraphQL compile

Amplify CLI Version 4.17.2

Issue Analytics

  • State:closed
  • Created 3 years ago
  • Comments:8 (7 by maintainers)

github_iconTop GitHub Comments

3reactions
edwardfoylecommented, Apr 14, 2020

Hi @kldeb yes you are correct, you’ll need to store the referralId with the customer. Unfortunately there’s no great workaround to #3275 at this time. You might be able to get the behavior you want by putting a placeholder value for referralId in the customer record if there is no referralId for the customer:

type Customer @model {
	id: ID!
	referredBy: Referral @connection(fields: ["referralId"])
	referralId: ID!
	name: String!
}

type Referral @model {
	id: ID!
	name: String!
}

When creating a customer without a referral, you can put a placeholder value in the referralId which means that the referredBy field is going to come back null in queries.

I’m going to close this issue and you can track the progress of optional connections in #3275

0reactions
github-actions[bot]commented, May 25, 2021

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.

Read more comments on GitHub >

github_iconTop Results From Across the Web

One-to-one relationships
In a one-to-one relationship, one record in a table is associated with one and only one record in another table. For example, in...
Read more >
What Is a One-to-One Relationship in a Database? - Vertabelo
A one-to-one relationship is a relationship where a record in one table is associated with exactly one record in another table. This type...
Read more >
One-to-one (data model) - Wikipedia
In a relational database, a one-to-one relationship exists when one row in a table may be linked with only one row in another...
Read more >
One-to-one relationship - Progress Documentation
A one-to-one relationship exists when each row in one table has only one related row in a second table. For example, a business...
Read more >
One to one relationship examples in Database | T4Tutorials.com
One-to-One Relationship exists when a single record in the 1st table is having a relationship with only one record in the 2nd table,...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found