modelgen bug with Has One @connection relation with an explicit field
See original GitHub issueDescribe the bug Related to this issue in JS: https://github.com/aws-amplify/amplify-js/issues/6560
amplify codegen models
is incorrectly handling Has One relations. The associatedWith
field is not being set to the field specified in the fields
argument.
The following model:
type Project @model {
id: ID!
name: String
teamID: ID!
team: Team @connection(fields: ["teamID"])
}
Gets modelgen’d to
"Project": {
"name": "Project",
"fields": {
"id": {
"name": "id",
"isArray": false,
"type": "ID",
"isRequired": true,
"attributes": []
},
"name": {
"name": "name",
"isArray": false,
"type": "String",
"isRequired": false,
"attributes": []
},
"teamID": {
"name": "teamID",
"isArray": false,
"type": "ID",
"isRequired": true,
"attributes": []
},
"team": {
"name": "team",
"isArray": false,
"type": {
"model": "Team"
},
"isRequired": false,
"attributes": [],
"association": {
"connectionType": "HAS_ONE",
"associatedWith": "id"
}
}
},
"syncable": true,
"pluralName": "Projects",
"attributes": [
{
"type": "model",
"properties": {}
}
]
},
Amplify CLI Version
4.29.2
To Reproduce
Run amplify codegen models
on the following schema:
type Project @model {
id: ID!
name: String
teamID: ID!
team: Team @connection(fields: ["teamID"])
}
type Team @model {
id: ID!
name: String!
}
Expected behavior
I would expect that team: Team @connection(fields: ["teamID"])
should result in:
"team": {
"name": "team",
"isArray": false,
"type": {
"model": "Team"
},
"isRequired": false,
"attributes": [],
"association": {
"connectionType": "HAS_ONE",
"associatedWith": "teamID"
}
}
Issue Analytics
- State:
- Created 3 years ago
- Comments:7 (5 by maintainers)
Top Results From Across the Web
Modelgen: Mining Explicit Information Flow Specifications ...
Abstract—We present a technique to mine explicit information flow specifications from concrete executions. These specifications.
Read more >Khapra Beetle - USDA APHIS
The Khapra Beetle(Trogoderma granarium ) is one of the world's most destructive pests of stored grain products and seeds. Its feeding damage often...
Read more >rice bug - Leptocorisa acuta
Upon adult emergence in the spring, rice bugs feed on wild host plants for one or two generations before migrating into rice fields....
Read more >Bed Bugs Appearance and Life Cycle | US EPA
Knowing what to look for is the first step in identifying and controlling bed bugs. There are many bugs that look like bed...
Read more >hibernate gradle
One of the layers is a DAO (Repository) layer. The exception I am getting is from maven project. Gradle will visit each sub-project...
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 find an interesting thing on the difference between
BELONGS_TO
andHAS_ONE
. According to this post, it saysAfter checking the amplify docs, this is the case for A
HAS_MANY
Bs and BBELONGS_TO
A. In contrast,BELONGS_TO
is not mentioned inHAS_ONE
section. If we take the prerequisite above, we can find that Team actuallyHAS_ONE
Project and ProjectBELONGS_TO
Team, which is just the opposite to the current output.Hence, I think the correct output should result in:
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.