objectbox / objectbox-dart

Flutter database for super-fast Dart object persistence
https://docs.objectbox.io/getting-started
Apache License 2.0
927 stars 115 forks source link

Entity Inheritance #249

Open obrunsmann opened 2 years ago

obrunsmann commented 2 years ago

Is Entity Inheritance already supported? @BaseEntity annotation seems not yet to be available. Maybe you could add a hint to the docs if it is not yet supported on dart.

https://docs.objectbox.io/advanced/entity-inheritance

greenrobot commented 2 years ago

Docs are updated. Now, let's leave that issue as a feature request to track interest.

XilinJia commented 2 years ago

Wonder what's the behavior in Dart with model inheritance?

Say I have a Base class (which is not annotated, so it's not persisted as documented) and a Sub class (annotated with @Entity) that extends from the Base class. So the properties defined in Sub are persisted as for a normal entity and the inherited properties from Base are not persisted. Is this correct?

vaind commented 2 years ago

Better a late answer then none :) @LeoK987

So the properties defined in Sub are persisted as for a normal entity and the inherited properties from Base are not persisted. Is this correct?

Yes, that's what happens. You can see it in action here: https://github.com/objectbox/objectbox-dart-performance/blob/main/lib/model.dart

natgross commented 2 years ago

Currently in Dart, is there a [trick] way where the base class as well as the subclass' properties are persisted as one entity? (namely as the subclass).

If not, would it help that I define the entity relationships in Java, but you still generate dart code from it?

raphire08 commented 2 years ago

It would be helpful to have this feature in dart as well.

Is there any work around to have an abstract class defined in the Entity class in a 1:1 relationship. For example

abstract class Shape {}

class Circle implements Shape {
  int id = 0;
  int? radius;
}

class Square implements Shape {
  int id = 0;
  int? side;
}

class ShapeModel {
  int id = 0;
  final shape = ToOne<Shape>();
}

basically in my case the nested child in json structure has different key value pairs and I cannot save it as Map

bgervan commented 2 years ago

I would need this feature too

ccg-barbri commented 2 years ago

I also need this feature to be able to implement common fields on multiple entities

nmoreyra commented 2 years ago

I also need this to be able to reuse code

yamilaBacchini commented 2 years ago

I don't understand why this is available on the other platforms but not in Dart/Flutter. It's the correct way to share multiple fields in different entities...

crapaluciano commented 2 years ago

hello, i want this feature

Siarl commented 2 years ago

This would be great to have

iabdousd commented 2 years ago

This is a huge limitation for me, it will be great to have it specially due to the fact that it's available in the other platforms versions.

Paroca72 commented 2 years ago

Here the same

schusterbenjamin commented 2 years ago

I also would be very happy once this feature gets released! 🚀

RicardoRB commented 2 years ago

Is there any plan to implement it? :)

danieloquelis commented 1 year ago

still not a resolution for dart?

christiancg commented 1 year ago

There have been a lot of comments here. The "needs more interest" label should be removed

danieloquelis commented 1 year ago

Exactly, how come 'needs more interest'? inheritance its an essential and crucial thing, it should be already included!!! Please

greenrobot-team commented 1 year ago

Please thumbs up the original post, this helps us track interest!

DJ2695 commented 1 year ago

This feature is pretty important to comply with the DRY principle and ensure that some type of entities have specific properties , especially in bigger projects with lots of entities. Looking forward to an implementation! 👍🏽

Only Workaround I see for now is using getter and setter and implementing them, like @vaind mentioned in here :

Better a late answer then none :) @LeoK987

So the properties defined in Sub are persisted as for a normal entity and the inherited properties from Base are not persisted. Is this correct?

Yes, that's what happens. You can see it in action here: https://github.com/objectbox/objectbox-dart-performance/blob/main/lib/model.dart

gorkemunuvar commented 1 year ago

Please consider implementing this feature, otherwise using workarounds or not using inheritance for objectbox entities is prevents creating good structured models.

jttuboi commented 1 year ago

It really sad to give up of a good database because one of the good feature for OOP is not implemented.

MBjoern commented 1 year ago

Waiting eagerly for this feature! Hereby showing my interest here

greenrobot-team commented 1 year ago

If you are interested in this please thumbs up the original post, this helps us track interest!

huynn0105 commented 1 year ago

Is there any plan to implement it? :)

navyzhou926 commented 1 year ago

why not support this feature? It is so important

greenrobot commented 1 year ago

For this issue, the goal and how to get there is clear. Thus, further conversations will be locked to prevent people just indicating interest: this should be done via :+1: at the issue description at the top :arrow_up:. This is the best way to track interest.

greenrobot-team commented 1 year ago

Unlocked so people can thumbs up the first post if interested!

Note: from a software engineering perspective it is a good idea not to have inheritance in your model files. It may seem to make things easier at first (less code, faster time to implement), but can lead to issues later (model changes, hard to uncouple).

Anyhow, as said, if interested, thumbs up the first post! This helps us track interest.