-
-
Notifications
You must be signed in to change notification settings - Fork 4k
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
Non-owning relationship fields in entity types #24653
Comments
Owner side is a not concept that should be applied to every database. But prior to v8 it was applied to jdl, so it was applied to the entire JHipster.
In every relationship, except example 2, the owner side is the left. Design that can be changed (enhancements):
This was partially explained in #24076 You can accomplish the desired behavior by converting the bidirectional OneToMany relationship to a unidirectional ManyToOne relationship.
To (unidirectional ManyToOne):
|
Thanks for explaining @mshima, but I am aware about how the relationships work. In this issue, I wanted to discuss how the relationships are represented in the TypeScript types, as I think they might be improved. Regardless of how the relationships are implemented, the API should be described as precisely as possible. Or are these topics intertwined and have to be thought out together? |
See #24350. We could add a property to hide from types, but I wonder if it’s worth. |
So in other words, the issue is that for some backend options the capabilities of the API change and relationships may or may not be provided. What exactly do you mean by adding a property? In the templates for the type generation? I figure that changing frontend types depending on backend options would introduce complexity and be a maintance burden. Considering this I am also not sure if it's worth it. |
We do have an option to manually eager load a relationship https://github.com/jhipster/generator-jhipster/blob/main/generators/app/README.md#eager-loading-relationships. |
Overview of the feature request
In PR #19098 the Angular entity model template was changed so that only fields are included for related entities if the entity is on the owning side. For React and Vue it still showed fields for all relationships.
I assumed only the owning side relationships to be shown to be the correct behavior, and that it was just not changed for React and Vue yet.
But recently in 52aad30 it was changed back to also include non-owning side relationships.
That makes me wonder if entity types should actually include non-owning side relationships or not.
e.g. JDL like following:
generates following types (example generated using Angular, but it's similar for React and Vue):
This might make one think that it's possible to create or retrieve
EntityA
withEntityB
's attached, but that is in fact not possible. This was the root issue that caused confusion and resulted in #19780.My proposal is to only include fields that can actually be used in the entity types as it was done in #19098 for Angular and to make this behavior consistent across client frameworks.
But I might be missing a use case for why non-owning side relationship fields must be present in the entity types, and I am eager to hear your thoughts.
Motivation for or Use Case
TypeScript types are more useful if they precisely describe the actual JavaScript objects. A mismatch can cause confusion and lead to bugs.
Related issues or PR
Bidirectional One-To-Many relationships not generating #19780
angular: improve form service #19098
Checking this box is mandatory (this is just to show you read everything)
The text was updated successfully, but these errors were encountered: