-
Notifications
You must be signed in to change notification settings - Fork 1.8k
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
Inheritance / Polymorphism #761
Comments
Any estimate on a time frame for this? I'm hoping to use Realm in an upcoming project, but without support for Model inheritance I'll have to hold off on trying it out. Looking forward to where you guys take this project though! |
Hi @T-Spoon |
👍 |
Still no estimates? Going to write a lot of duplicate code since I want to use Realm anyways. Works fine in swift already. Monitoring this. |
Unfortunately not. The support for this in Objective C and Swift is actually just sharing fields. It is not proper polymorphism. This is good enough for some use cases, but we feel that without being able to query on abstract super classes it will be less useful on Android. Right now we are focusing on migrations, null support and async querying, but hopefully we will be able to tackle this afterwards. |
@cmelchior So is there any way to share fields on Android? We have 5 models that all share the same synchronization-related fields and code. We use inheritance in our current SQLite models; if we switch to Realm, will we have to duplicate the synchronization fields across each of the 5 model classes? As a workaround, I'm thinking about having those classes implement an interface with getters and setters for the shared fields, which at least let me share the synchronization code... is there a better way? |
While waiting for this inheritance feature to be available, is there any workaround, like a good practice to design our RLMObjects and model to make such use cases possible? My need is with a typical object model having, say, Animals objets, subclassed as Dogs and Cats, and I want sometimes to fetch all the Animals (to display in a List only common properties of those animals like their name), and sometimes (e.g. when I tap on an item in the list to show the details) to access properties of the specific class Dog or Cat. Given that I can't use inheritance to represent that in Realm yet, how would you guys represent your data model instead to make this use-case possible? Adding a relationship from the Dog and Cat RLMObjects to the Animal RLMObject (composition instead of inheritance) maybe? |
The current solution is to use composition instead of inheritance. On the other hand we are considering to allow inheritance, but it would not allow queries. |
@emanuelez Is @AliSoftware's composition-over-inheritance example what you have in mind? |
See other model: Im have base object public abstract class BaseObject {
private String guid;
private Map<String, String> name;
private List<String> tags;
private double latitude;
private double longitude;
private LatLng position;
@Nullable
public String getName(String locale) {
if (name != null) {
return name.get(locale);
}
return null;
}
public String getName() {
return getName(getDefaultLocale());
}
} and some other child public class City extends BaseObject {
int version;
boolean current = false;
} public class Station extends BaseObject {
Map<String, String> next;
List<String> routes;
private List<String> bus;
private List<String> shuttle;
private List<String> tram;
private List<String> troll;
} public class RoutePoint extends BaseObject {
int direction;
String routeGuid;
} and few other |
Hi, is there any update about this issue? |
I am also eagerly waiting for this feature. |
I'm also )) |
Is there any update on this? |
You can check the road map where it is mentioned that it will happen one day. (I am not a member of Realm) |
And here we are, at 2 years and a half since "I can promise that it won't take another year." (#761 (comment)) sigh :( |
hey all, product from Realm here, I am in the middle of writing the production description for this feature right now. As you might have guessed since almost no other databases exposes polymorphic inheritance, but rather leaves it up to the developer to build themselves, this is an incredibly difficult feature to build - but rest assured we are planning to build it. As mentioned in some of the comments above we had other high priority tasks we needed to complete first which would lay the foundation before inheritance - for instance we have released Cascading Deletes and are working on Maps and Mixed types right now which would be necessary for Polymorphism. Stay tuned. |
Not sure why people still choose to use Realm with its heavy-handed restrictions. I'm forced to deal with it because of legacy code. ObjectBox is NoSQL and has supported inheritance for 2 years. You can also use the object across threads, in contrast to Realm. |
Any updates on this? |
In 2021 Inheritance / Polymorphism is not implemented yet. I have just switched to ObjectBox. Good job! |
I still don't feel like unsubscribing to this thread. I think I have developed some nostalgic connection with this thread now. Whenever it is revived by a new comment, it puts a smile on my face..and in my mind "Cause we were just kids when we fell in love" :') |
@kanikaverma7 love that last comment! As another alternative, we choose this little library for building a simple serialized and indexed object cache on disk. You can serialize your model objects using GSON and have all the inheritance you want. Super lightweight and works great for most simple caching use cases. |
Sorry I should hav posted an update to this ticket as soon as we had new information. We have finished the Initiative writeup and it has been approved internally - but Inheritance is just one part of this Initiative, there are still a couple projects we need to implement before we start Inheritance. One of these migrations, you can imagine with Polymorphism that migrations will become a lot more complicated and we'd like to overhaul this feature so that users can start using Inheritance in production on Day 1. Another is we need to add some features to MongoDB Realm Schema so that our sync users can enjoy this feature too - for instance, we need to add the ability for $anyOf, $allOf, and $oneOf to our JSON schema support (which is how we plan to model Inheritance on the server-side). Polymorphism is actually utilized extensively in MongoDB so we expect sync clients to be some of our biggest users of Inheritance. We also need to wait for the Android team to have some free cycles. If you're not aware, the Android team has been heads down on building on a purely Kotlin SDK. This comes with Multiplatform support out of the box and since we are building the SDK from the ground up we've taken this opportunity to address some longstanding functionality that has turned off some users. Most notably, the thread confinement of Realm Objects - this becomes an issue for developers who are used to programing with Coroutines natively. And if you will at the upcoming DroidCon's please look out for a Realm presentation or booth diving deep into our new Kotlin SDKK - stay tuned! So we have our hands full - I realize that this has been an issue for several years now but we've had a few "small" things happen in our business and technology space that we've had to prioritize - but we have now officially added it to our medium term roadmap and internally, we look forward to working on this and delivering it for our community. |
To save some time for those who's looking to move from Java to Kotlin SDK, it seems that neither inheritance nor delegation works. Here's a simple test I did. realm/realm-kotlin#801 If only I had known this sooner. |
Hi! This is kinda nostalgic thread now. Any updates on this feature? Anything in the pipeline related to inheritance and polymorphism? |
I decided to unsubscribe to this thread. We had to come up with something to support polymorphism in our SQLite database (Using Room for android atm), and it worked. A little more boilerplate code, but it does the job. |
This approach worked back in 2015 and still works to this day btw |
Any updates on this feature? |
@ianpward would you mind giving a "State of the Union" update on Realm inheritance? Your last such update in Summer 2021 was extremely helpful. We are looking to make some large architecture decisions based on inheritance support (in the Swift client for now, but Android just the same), so would be great to feel out a realistic timeframe for this – ie: is it imminent / expected this year VS not. Cheers! |
can't believe this issue still open |
Almost 10 years for a feature, it seems like the team still has other priorities to concern. To me, realm is still an immature library to use. This issue is just one of those basic features that are being requested out there. |
Inheritance / Polymorphism is a core concept of modern software development. Do they have a timeline? |
I am glad that I encountered this problem at the start of using Realm. What is the benefit of NOSQL if the table fields are fixed as in SQL? |
@longbombus I'd be a little more concerned about the fact that the database is now fully abandoned by MongoDB (see the Atlas Device SDK deprecation docs) Which is sad, technically it was pretty easy to do Inheritance, you did it manually with a discriminator field. Sure, it definitely wasn't first-party, but the workaround was doable. I dislike issues that have no workarounds. And stability concerns. Still, there was a lot of potential, but also a lot of potential lost to the 5 iterations of Realm Sync. |
A highly request feature is polymorphism. Mostly for use in ListAdapters, but a lot of other scenarios exists.
We need support for the following:
Example
The text was updated successfully, but these errors were encountered: