Skip to content

Refactor TableRow and the way it is implemented to allow to use inheritance on Models with Database #2711

Closed

Description

@BenAuerDev

With implementing #2710 we have the option to use the extends keyword in a yaml-file when declaring our model.

class: BaseClass
fields: 
  fieldOne: String
class: SubClass
extends: BaseClass
fields: 
  fieldTwo: String

Which generates a class that can be used like:

SubClass(fieldOne: '...', fieldTwo: '...');

BUT this is not yet possible with classes that have a table property, as a class with table-property is generated extending TableRow

abstract class MyClass extends TableRow ....

Describe the solution you'd like
Change TableRow to be an interface kind of like:

abstract interface class NewTableRow {
  int? id;

  Table get table;
}

This way we can implement the TableRow instead of extending it.

abstract class SubClass extends BaseClass
    implements _i1.TableRow, _i1.ProtocolSerialization {

Describe alternatives you've considered
Allow inheritance only for data-classes but not for classes related to a database

Additional context
Add any other context or screenshots about the feature request here.

Activity

  1. added
    enhancement
    area: models
    on Sep 4, 2024
  2. SandPod commented on Sep 4, 2024

    @SandPod
    Contributor

    This should be an OK change to make since normal usage of the framework should not rely on the model class receiving its TableRow and fields definition through inheritance rather than interface implementation.

  3. moved this from Now 🔥 to Done 🚀 in Serverpod Frameworkson Sep 25, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

area: modelsenhancement

Type

No type

Projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions