objectbox-dart icon indicating copy to clipboard operation
objectbox-dart copied to clipboard

Entity Inheritance

Open obrunsmann opened this issue 3 years ago • 28 comments

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

obrunsmann avatar May 21 '21 18:05 obrunsmann

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

greenrobot avatar May 22 '21 09:05 greenrobot

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?

XilinJia avatar Jun 08 '21 18:06 XilinJia

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

vaind avatar Jul 15 '21 07:07 vaind

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?

natgross avatar Jul 30 '21 11:07 natgross

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

raphire08 avatar Aug 03 '21 13:08 raphire08

I would need this feature too

bgervan avatar Sep 06 '21 10:09 bgervan

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

ccg-barbri avatar Nov 09 '21 21:11 ccg-barbri

I also need this to be able to reuse code

nmoreyra avatar Nov 09 '21 21:11 nmoreyra

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...

yamilaBacchini avatar Nov 10 '21 21:11 yamilaBacchini

hello, i want this feature

crapaluciano avatar Nov 12 '21 17:11 crapaluciano

This would be great to have

Siarl avatar Dec 12 '21 23:12 Siarl

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.

iabdousd avatar Feb 01 '22 13:02 iabdousd

Here the same

Paroca72 avatar Mar 13 '22 03:03 Paroca72

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

schusterbenjamin avatar Mar 16 '22 17:03 schusterbenjamin

Is there any plan to implement it? :)

RicardoRB avatar Apr 27 '22 16:04 RicardoRB

still not a resolution for dart?

danieloquelis avatar May 26 '22 20:05 danieloquelis

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

christiancg avatar May 26 '22 20:05 christiancg

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

danieloquelis avatar May 26 '22 21:05 danieloquelis

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

greenrobot-team avatar May 30 '22 06:05 greenrobot-team

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

DJ2695 avatar Jun 12 '22 09:06 DJ2695

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

gorkemunuvar avatar Jul 29 '22 10:07 gorkemunuvar

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

jttuboi avatar Aug 14 '22 02:08 jttuboi

Waiting eagerly for this feature! Hereby showing my interest here

MBjoern avatar Sep 01 '22 13:09 MBjoern

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

greenrobot-team avatar Sep 06 '22 06:09 greenrobot-team

Is there any plan to implement it? :)

huynn0105 avatar Sep 23 '22 09:09 huynn0105

why not support this feature? It is so important

navyzhou926 avatar Nov 02 '22 02:11 navyzhou926

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 avatar Nov 02 '22 06:11 greenrobot

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.

greenrobot-team avatar May 08 '23 06:05 greenrobot-team