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
Support for inheritance in protocol/*.yaml files #793
Is your feature request related to a problem? Please describe.
The problem with the lack of support for inheritance is that this is the only thing that dart does not provide a workaround for. If you wish to add functions or setters/getters to a generated object then you can simply extend that class which is a built in feature of dart. However, there is currently nothing you can do if you wish to have one of your serverpod classes inherit another one of your serverpod classes to achieve things like polymorphism.
Describe the solution you'd like
Similar to the way you specify the "class: ClassName" and the "table: table_name", there should be a third option for "inherits: InheritedClassName"
Describe alternatives you've considered
alternatively, you could follow the standard dart naming convention and use "extends: InheritedClassName". This would allow for future additions for the "implements: InterfaceClassName" and "with: MixinClass1, MixinClass2, MixinClass3". Although in order for these to work you would need a way in your serverpod object to specify the class type and whether it is a Class, Interface, or Mixin
Additional context
This has been the single largest issue for me and my dev team as we use serverpod in our production application with the only alternative being to manually define classes and use the freezed package however we wish to continue using the simple syntax provided by serverpod.
Reacted by braj065, gecko20, Abhisek De, Daniel Montibeller and Christian Elster
I want to use message streaming to notify my clients of updates to models. The following code compiles, and the endpoint sends the message, but the clients never receive it, because the deserialization gets messed up.
I spent hours trying to figure out why messages weren't being received, then when I removed the entity field, everything worked fine.
This is all because inheritance is not supported. Why can't we even use SerializableEntity as a generic type so my entity can be dynamic?
(Also, the serverpod:ModelClass thing is totally undocumented, I discovered it by accident.)
@tgrushka I think what you are asking for here is different from inheritance on the classes them self's.
You want to use a base model of a type so that you can add the classes that extends the base model. I think this will more or less be impossible to resolve as we will not know the type we need to serialize / de-serialize into. I presume you actually want the full class not just the base one defined here.
However I think the solution here is to support Generic types, where you could maybe define something like this:
class: UpdateMessage<T>fields:
user: module:auth:UserInfoaction: UpdateActionentity: T
Then we should be able to embed enough information in the message to resolve the datatype, but as dart doesn't support reflections the implementation details may be pretty tough. Related discussion here: #1035.
Activity
wstrange commentedon Mar 29, 2023
This underscores one of the issues with using yaml to generate Dart, instead of just using native Dart + annotations.
Older discussion but still relevant: #186
tgrushka commentedon Jul 27, 2023
I want to use message streaming to notify my clients of updates to models. The following code compiles, and the endpoint sends the message, but the clients never receive it, because the deserialization gets messed up.
I spent hours trying to figure out why messages weren't being received, then when I removed the
entityfield, everything worked fine.This is all because inheritance is not supported. Why can't we even use
SerializableEntityas a generic type so myentitycan be dynamic?(Also, the
serverpod:ModelClassthing is totally undocumented, I discovered it by accident.)Isakdl commentedon Jul 28, 2023
@tgrushka I think what you are asking for here is different from inheritance on the classes them self's.
You want to use a base model of a type so that you can add the classes that extends the base model. I think this will more or less be impossible to resolve as we will not know the type we need to serialize / de-serialize into. I presume you actually want the full class not just the base one defined here.
However I think the solution here is to support Generic types, where you could maybe define something like this:
Then we should be able to embed enough information in the message to resolve the datatype, but as dart doesn't support reflections the implementation details may be pretty tough. Related discussion here: #1035.
SandPod commentedon Aug 29, 2024
Closing this issue and will reference the discussion from the RFC for model inheritance here: #1873