Skip to content

Feature Request: Ability to Use Subtypes of an Entity #2609

Closed

Description

@alexdess

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.

Activity

  1. SandPod commented on Aug 15, 2024

    @SandPod
    Contributor

    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.

  2. added
    in triage
    on Aug 15, 2024
  3. SandPod commented on Aug 19, 2024

    @SandPod
    Contributor

    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?

  4. alexdess commented on Aug 19, 2024

    @alexdess
    Author

    Thank you for your response.

    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.

    All of this, without resorting to raw queries.

  5. Isakdl commented on Aug 19, 2024

    @Isakdl
    Collaborator

    prevent updating all fields when I only want to update the comment field.

    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:

    await Company.db.updateRow(session, company, columns: [Company.t.name]);

    I think the update part could be handled under the hood by Serverpod when we have support for view tables.

  6. SandPod commented on Aug 19, 2024

    @SandPod
    Contributor

    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.

  7. removed
    in triage
    on Aug 19, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions