How to delete LinkingObjects from an Object in realm?

608 Views Asked by At

Lets say I have two models/objects for realm 1.0.0 - ArticleMO, and TagMO:

class ArticleMO: Object {
    dynamic var title: String = ""
    let tags = List<TagMO>()
}

class TagMO: Object {
    dynamic var name: String = ""
    let articles = LinkingObjects(fromType: ArticleMO.self, property: "tags")
}

How can I remove all articles with a tag?

I've tried:

if let tag = realm.objects(TagMO).filter("name == '\(tagName)'").first {
    realm.delete(tag.articles)
}

But it results in an error like this:

RLMArray has been invalidated or the containing object has been deleted

All my attempts around the issue - such as iterating through the objects after trying to store/detach them, result in the same error. What am I missing?

0

There are 0 best solutions below