You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
Feature Request: Ability to Use Subtypes of an Entity #2609
Is your feature request related to a problem? Please describe.
I would like to suggest a feature enhancement that allows the use of subtypes for entities. In my application, I work with an entity called "transaction" which contains a large number of fields. However, there are cases where I only need to display a few of these fields in certain views, and I currently don't see a straightforward way to accomplish this.
This limitation could potentially impact the performance and usability of the application as it evolves.
Describe the solution you'd like
A way to declare a subentity.
Describe alternatives you've considered
A possible alternative would be to do it manually: create shared DTOs and manage the DB entity on the server side only.
Context
As a developer with a .NET background, I'm familiar with using tools like AutoMapper coupled with Entity Framework Core to manage such scenarios efficiently. I believe having a similar capability in this context would greatly enhance flexibility and optimize resource utilization.
You would like to modify the same data source but be able to create different representations?
Yes, that's correct. The idea is to be able to create different representations or models of the same data source to suit specific needs, without overfetching data or unnecessarily updating unrelated fields.
I believe this issue is indeed related to a modifiable view. Here’s a more concrete example of the problem:
Let's imagine a 'Transaction' table with hundreds of columns or a column with a large amount of data (for example, a JSON of points).
Now, if I want to have a window where I list my transactions displaying only the transaction number and date, I would like to create a model with just these two fields to avoid overfetching. A view combined with a model tied to this view could address this need.
However, if I have a second editing interface where the user can add a comment to a transaction, I would also like to use a model that represents only this view. This would avoid overfetching when loading the transaction and prevent updating all fields when I only want to update the comment field.
This sounds like modifiable views, I'll close this issue as a duplicate on that but link to it as a concrete example of use cases that it would support.
Activity
SandPod commentedon Aug 15, 2024
Hey @alexdess!
This sounds like a duplicate of #1873.
Would that feature cover your use case?
If not, please elaborate on what differentiates this feature request from inheritance.
SandPod commentedon Aug 19, 2024
Or could this possibly be more connected to view tables? #228
You would like to modify the same data source but be able to create different representations?
alexdess commentedon Aug 19, 2024
Thank you for your response.
Yes, that's correct. The idea is to be able to create different representations or models of the same data source to suit specific needs, without overfetching data or unnecessarily updating unrelated fields.
I believe this issue is indeed related to a modifiable view. Here’s a more concrete example of the problem:
Let's imagine a 'Transaction' table with hundreds of columns or a column with a large amount of data (for example, a JSON of points).
Now, if I want to have a window where I list my transactions displaying only the transaction number and date, I would like to create a model with just these two fields to avoid overfetching. A view combined with a model tied to this view could address this need.
However, if I have a second editing interface where the user can add a comment to a transaction, I would also like to use a model that represents only this view. This would avoid overfetching when loading the transaction and prevent updating all fields when I only want to update the comment field.
All of this, without resorting to raw queries.
Isakdl commentedon Aug 19, 2024
This part is supported already, but I just realised we have not documented this feature! So created a PR for it here: serverpod/serverpod_docs#149
In short to update a one or more specific column(s) you can do that by specifying the columns you want to change, like so:
I think the update part could be handled under the hood by Serverpod when we have support for view tables.
SandPod commentedon Aug 19, 2024
This sounds like modifiable views, I'll close this issue as a duplicate on that but link to it as a concrete example of use cases that it would support.