Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Entity Inheritance #249

Open
obrunsmann opened this issue May 21, 2021 · 28 comments
Open

Entity Inheritance #249

obrunsmann opened this issue May 21, 2021 · 28 comments
Labels
enhancement New feature or request

Comments

@obrunsmann
Copy link

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 obrunsmann added the enhancement New feature or request label May 21, 2021
@greenrobot
Copy link
Member

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

@XilinJia
Copy link

XilinJia commented Jun 8, 2021

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 vaind added the needs more interest Currently not prioritized for implementation, waits for more upvotes label Jun 24, 2021
@vaind
Copy link
Collaborator

vaind commented Jul 15, 2021

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
Copy link

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
Copy link

raphire08 commented Aug 3, 2021

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

This comment was marked as spam.

@ccg-barbri
Copy link

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

@nmoreyra

This comment was marked as spam.

@yamilaBacchini
Copy link

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

This comment was marked as spam.

@Siarl

This comment was marked as spam.

@iabdousd

This comment was marked as duplicate.

@Paroca72

This comment was marked as spam.

@schusterbenjamin

This comment was marked as spam.

@RicardoRB

This comment was marked as spam.

@danieloquelis

This comment was marked as spam.

@christiancg

This comment was marked as spam.

@danieloquelis

This comment was marked as spam.

@greenrobot-team
Copy link
Member

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

@greenrobot-team greenrobot-team removed the needs more interest Currently not prioritized for implementation, waits for more upvotes label May 30, 2022
@DJ2695
Copy link

DJ2695 commented Jun 12, 2022

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

This comment was marked as duplicate.

@jttuboi

This comment was marked as duplicate.

@MBjoern

This comment was marked as duplicate.

@greenrobot-team
Copy link
Member

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

@huynn0105

This comment was marked as duplicate.

@navyzhou926

This comment was marked as duplicate.

@greenrobot
Copy link
Member

greenrobot commented Nov 2, 2022

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 👍 at the issue description at the top ⬆️. This is the best way to track interest.

@objectbox objectbox locked as off-topic and limited conversation to collaborators Nov 2, 2022
@objectbox objectbox unlocked this conversation May 8, 2023
@greenrobot-team
Copy link
Member

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

No branches or pull requests