-
Notifications
You must be signed in to change notification settings - Fork 2.2k
Add support for cascading deletes #1186
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
Comments
Is this still in the works? |
Yes, we'll post here as soon as we have something to share. |
Anything new about this Issue / Feature. It's really hard to keep the database consistency with this feature missing. |
Looks like this is working well in core now (as of realm/realm-core#867), so it should just be a matter of exposing it through the Objective-C & Swift APIs. |
Any estimation on how long until this feature is implemented and exposed? |
Interested in this as well :) |
We're currently actively working on a last conceptual question around this issue in core, which we want to see resolved so that we're able to keep the related APIs as intuitive as possible. We can't give yet an exact ETA, but we'll keep you posted with our further progress and are looking forward to be able to expose it as much as you. |
That would definitely helpful. |
I have write a Helper , you can just delete all the object with one line code. I just read all the Realm property value and delete it. maybe it will help you. check out at :https://github.com/com314159/RealmDeleteCascad
|
Looks interesting, but not exactly "safe to use" in a production environment with thousands of users :D |
+1 |
+1 |
1 similar comment
+1 |
Any update on this issue? This feature is one of the big factors holding me back from adopting Realm. |
If that helps anyone, I'm using an alternative approach in the mean time: a kind of garbage collection. The idea is that there's a realm entity called - (void)performGarbageCollection {
NSDate *startOfGCDate = [NSDate date];
NSError *error;
NSString *temporaryRealmName = @"tmp";
// Rename all realm files to tmp
[self.realm writeCopyToPath:... error:&error]; //generate path to temporaryRealmName
[self.realm beginWriteTransaction];
[self.realm deleteAllObjects];
[self.realm commitWriteTransaction];
// move the data
RLMRealm *sourceRealm = [OFMObjectCache realmForDomain:temporaryRealmName];
[self.realm beginWriteTransaction];
RLMResults *rootClasses = [RootClassIdentifier allObjectsInRealm:sourceRealm];
for (RootClassIdentifier *rootClassIdentifier in rootClasses) {
Class aClass = NSClassFromString(rootClassIdentifier.className);
for (id object in [aClass allObjectsInRealm:sourceRealm]) {
[aClass createOrUpdateInRealm:self.realm withObject:object];
}
}
[self.realm commitWriteTransaction];
sourceRealm = nil;
NSFileManager *fm = [[NSFileManager alloc] init];
NSString *pathForTmp = ...;//get the path to the tmp realm
NSDirectoryEnumerator *enumerator = [fm enumeratorAtPath:pathForTmp];
// Remove tmp files
for (NSString *fileName in enumerator) {
NSString *absoluteString = [pathForTmp stringByAppendingPathComponent:fileName];
BOOL isDirectory = NO;
[fm fileExistsAtPath:absoluteString isDirectory:&isDirectory];
if (!isDirectory) {
NSRange range = [fileName rangeOfString:temporaryRealmName];
if (range.location != NSNotFound) {
BOOL result = [fm removeItemAtPath:absoluteString error:&error];
if (!result) {
// handle error
}
}
} else {
[enumerator skipDescendants];
}
}
NSDate *endOfGCDate = [NSDate date];
NSLog(@"Garbage collection took %.3lf", [endOfGCDate timeIntervalSinceDate:startOfGCDate]);
} Adding root classes goes like this: [self.realm beginWriteTransaction];
[self.realm addOrUpdateObject:[[OFMRootClassIdentifier alloc] initWithClassName:NSStringFromClass(self.class)]];
[self.realm commitWriteTransaction]; And happens in the init method of classes that have as data models any of those root entities. |
Outside of Core6 upgrade the biggest blocker for cascading deletes is to make support for that with sync. That's a bit tricky, and we currently don't have a committed timeframe for that, unfortunately. But this issue will surely be updated ones we have more info. |
Any update on this issue? |
Or it could be supported for non-sync Realms only until Sync supports it 😄 |
Almost 4 years since the opening of this issue. For a feature that comes built-in with CoreData. It's kind of disappointing that Realm isn't making this a priority. Slowly moving away from Realm because of this. |
Me too. |
Sybase has cascading delete triggers 30 years ago. Just sayin'. |
Is there any news on the implementation of this feature? |
Also very disappointed that this hasn't been implemented so far. I released my app and have had several complaints already about db being inaccessible (corrupted) so the app has to be removed and reinstalled. I try to ensure consistency by doing everything manually (cascade deletes, foreign keys, semantic uniques, migration from local to synced realm) but this is (evidently) far from ideal. This is basic functionality that the database should provide out of the box. Realm is very fragile and gets in an inconsistent state easily, resulting in unusable apps. Please improve this. |
bump |
Implemented Realm in my whole app, didn't know we would be encountering this issue at earliest. Creating hell lot of problem to manage the objects. How soon we will have this feature? |
@keshavkishore09, we are also waiting for the feature, but in the meantime there are enough solutions that can solve your problem until they release the cascade deletion. Check the answers above. To sum it up: what we did was extend the realm models with a new method that returns the properties/objects that should be cascade-deleted. Then for each such property/object we do the same until all is deleted. |
The PR for this feature is open since June 2018. This issue is being discussed since 2014. Make of that what you will, but at this point you should think about your in-house solution like many other people in this thread did. |
I'm not assuming this will help anyone, but I can at least spread a bit of light over our thinking. I can confirm that we are going to do this. It is "just" a matter of time and resources. So far we have not prioritized it high as there are workarounds, and we have focused on other bugs and features without workarounds. That's of course not useful for anyone wanting this feature. |
Hello! |
I can give a quick update. As you may have seen we have released a beta with Core6 and Frozen Objects (do try it out!) and expect the GA version in April. We are currently implementing " Embedded Objects" that will give you a similar functionality if it fits your data models. But it won't help you much for highly linked data models where you can't just embed one model in another. That is still something we will look into prioritizing this year. |
@bmunkholm Hello, can we give some updates on this? |
Embedded Objects was released a while back and would enable the cascading delete semantics in most cases. Have you looked at that? |
@bmunkholm oh, no, sorry. Thank you for quick response! Can you suggest on which version Embedded Objects was released? |
@bmunkholm ok, I found it. |
Is But...they aren't. The limitation that It's also possible I don't understand Realm's performance. Suppose I have:
Suppose I have 2,600,000 That can't be as fast as directly querying for the |
More and better cascading delete functionality is still on the roadmap, although not in the immediate future. We think embedded objects cover many of the cases where people want cascading deletes, but they definitely don't cover anything. WRT to the second half of your question, the best you can do currently is probably:
This is typically going to be significantly slower than Querying Child directly would be |
In my case, If I abandoned the
Would this query be reasonably the same performance as querying a
(Thanks for the guidance. It’s just very expensive in terms of dev time to try different approaches and profile them; I’m hoping your experience can point me down the best path.) |
We don't support using If each Child object has exactly one parent, or if there's more Child objects than Parent objects, then querying via a List on the parent should be a bit faster than either a query on the value over the link or a query on Child and looking up the parent from that. |
@tgoyne Thanks! In my case, the vast majority of (The list items are filepaths. Most It sounds like
should be performant, without needing the wrapper |
Yep, for that it sounds like a |
Blocked on support in core.
The text was updated successfully, but these errors were encountered: