Models defined in Swift synched to remote Realm


#1

As soon as a model is defined in Swift source code, it is replicated to my remote realm once the app runs. This happens without any code instantiating objects of that model having ever been written.

class ClassWithNoObjects: Object {
@objc dynamic var name = “”
}

I am curious why and how this happens. I would also like to know how to get rid of it. Realm Studio appears to be quite limited in what it can offer in terms of managing Realm data. For example, it does not seem possible to delete anything within a realm, only the realm itself in all of its entirety. What am I missing?


#2

@ikaz1 This is expected behavior by logging in with a valid user and opening a Realm with a valid schema you have created a Realm on the Realm Object Server. Studio allows you to view Realms on a Realm Object Server including ones with no objects - this is to verify the schema you want. I believe you can delete objects - have you tried right-clicking?


#3

Correct, I can delete an object using Delete command on the right click menu. I see two problems here:

  1. I can delete an object, but not a class. My issue was that for as long as I ever defined a class/model in my Swift code, I cannot get rid of it. Consequently erasing the class from my code has no effect and there is no right click menu on the class itself, only on objects of that class, if any exist.

  2. Deleting the parent object in a one-to-many model using Studio does not delete child objects. This effectively creates orphaned records. Same behavior is observed when deleting from Swift code.


#4

@ikaz1 Ah gotcha - yes currently we cannot delete a class with Studio - we hope to add this later.

Cascading deletes has been added to core but we haven’t exposed it in the bindings yet - hopefully soon. However, there are several examples online of how to implement this in code:


#5

Thanks for the info. Enforcing cascading deletes is not an issue in terms of coding. It’s just that we were hoping to avoid having to wrap the Realm object model in a “corrective” layer. But it looks like we’ll need to do just that to mitigate current limitations including this one as well as some other nuances of Realm’s programming model.

By this you mean neither in Studio nor from Swift code, correct? Because in my testing removing a class definition from code does not lead to its removal from Realm.


#6

Removing from Swift will not delete the schema you are correct - but the schema will not be available for the user to edit from the on :slight_smile:

I agree we should have this to clean up ROS but usually this is only an annoyance in development - we’ve been focusing on prod features and the cloud right now but hope to come back to it soon.