-
Notifications
You must be signed in to change notification settings - Fork 63
Android codegen bug: implicit @BelongsTo annotation not being applied to generated child models #102
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
Comments
@raphkim I am not sure whether this is a bug. According to the amplify doc, we only support explicit use case for type Post @model {
id: ID!
title: String!
comments: [Comment] @connection(keyName: "byPost", fields: ["id"])
}
type Comment @model
@key(name: "byPost", fields: ["postID", "content"]) {
id: ID!
postID: ID!
content: String!
post: Post @connection(fields: ["postID"])
} |
Every connection is bi-directional in nature; if a parent has a child, then a child has to have a parent. It simply doesn't make sense for the child to not belong to any parent. I do agree that our current doc suggests that bidirectionality is optional, which is simply not true. This must be addressed to clarify that while bidirectionality is a requirement, an explicit bidirectionality is optional (i.e. if "belongsTo" is not explicitly specified, then it is still assumed by the codegen/datastore). This is a requirement that doesn't come from customer demand; in fact, the customer will not even need to know that there is a To clarify, the customers may also explicitly specify a "belongsTo" relationship as you say by adding |
Here's another interesting example. Schema:
Current:
Expected:
|
@raphkim Not sure if the expected code snippet is correct. I try to make some code changes but find this part: amplify-codegen/packages/appsync-modelgen-plugin/src/visitors/appsync-visitor.ts Lines 458 to 459 in 588b9e4
So the targetName field is originally designed to be removed from the model. But from your output, you add BelongsTo to the targetName type itself, which is meant to be hidden from developer and should use model type instead.
Besides, this change will have impact on all the SDKs. I would like to get more contexts/data-points from other SDKs before making this changes. Nevertheless, I would suggest that the temporary solution is to inform the user to use the bi-direction schema instead. |
You are right! Fixing the "expected behavior" sections accordingly.
You are absolutely right. I will raise this with the other platforms for review. |
Hi @raphkim. Based on the above comments, closing this issue until we have a thumbs up from Datastore teams that we need to add |
Still an issue with v2. If |
Reopening per discussion w/ Android today. We should try to load this into the fix for #319 |
This shouldn't be tracked as an enhancement, but should instead be tracked as a bug, since this causes Cascading deletes in native platforms to fail. |
I synced up w/ @phani-srikar on this tonight. He's concerned that generating an implicit |
Issue
When the customer creates a GraphQL model schema with either hasOne or hasMany relationship, they are only required to explicitly specify
@connection
directive on the parent model (they do not need to explicitly mention belongsTo relationship on the child model). However, every relationship must be bi-directional and codegen should still generate child model with belongsTo relationship.Currently, android codegen does not behave this way and does not generate child model correctly.
Schema for reference:
This explicitly specifies a connection that
Post
has manyComment
, but does not specify a connection directive on theComment
side. This results in java codegen forming a@HasMany
relationship on thePost
side but generates aComment
model without@BelongsTo
connection to other models. Android DataStore depends on the explicit presence of this annotation when generating foreign key relationships.Currently behavior:
Expected behavior:
Note: This is a requirement for both one-to-one and one-to-many relationships
The text was updated successfully, but these errors were encountered: