Is there a way to access linking objects during migration? (Embedded objects)

I am trying to change a regular object to embedded. The requirements for to change the embedded ness is is that each embedded object can have one and exactly one object that is linked to it.

I know for sure that I have orphaned objects (zero parents) and want to make sure these gets deleted. If I fail to do this, the app will crash.

The question is. How do I find these orphaned children so I can delete them?

Class structure:

public class Parent:Object {
    let childList = List<Child>()
}

public class Child:EmbeddedObject  { //This used to be a regular object
       let parents:LinkingObjects<Parent> = LinkingObjects(fromType: Parent.self, property: "childList")
}

Some children does not have parents. Migration function.

migration.enumerateObjects(ofType: Child.className()) { (oldObject, newObject) in
     
            //How can I now that an old child object does not have a parent. 
           // oldObject?["parents"]  doesn't seem to exist
}

Any suggestions?

After reading this https://github.com/realm/realm-cocoa/issues/7145#issuecomment-827029259, I am convinced it is better to avoid this migration altogether and moving data to a new property instead.

This topic was automatically closed 5 days after the last reply. New replies are no longer allowed.