I just discovered EmbeddedObject in the RealmSwift SDK reference and tried implementing it like this:
public class WorkspaceMember: EmbeddedObject {
@objc public dynamic var _id: String = UUID.init().uuidString
@objc public dynamic var name: String = ""
@objc public dynamic var userId: String = ""
@objc dynamic var permission: Int = WorkspacePermission.read.rawValue
let workspace = LinkingObjects(fromType: Workspace.self, property: "members")
public var workspacePermission: WorkspacePermission {
return WorkspacePermission(rawValue: permission) ?? .read
}
}
public class Workspace: UniqueObject {
@objc public dynamic var title: String? = nil
@objc public dynamic var createdAt: Date = Date()
@objc public dynamic var active = true
public let members = List<WorkspaceMember>()
}
However, I am facing two problems that I cannot resolve and don’t see documented.
Compatibility with custom “objectTypes” in Configuration. In my RealmConfiguration, I want to specify the Types I use inside the “objectTypes” argument which expects an [Object.Type] input. However EmbeddedObject does not inherit from Object and cannot be passed here. When omitting it, I’m confronted with a Realm runtime error (WorkspaceMember not included in ObjectTypes)…
When not specifying ObjectTypes I’m seeing the following error in my local Sync log:
Failed to transform received changeset: Schema mismatch: 'WorkspaceMember' is an embedded table on one side, but not the other
Also when removing Configuration for Workspace and WorkspaceMember and deleting the table on the server, I’m seeing other errors (e.g. duplicate configuration). So a solution for 1. would probably help here as well.
Did anybody else experiment with EmbeddedDocument yet?
@Ian_Ward thank you for the fix for 1) Indeed I was now able to specify my objectTypes correctly. Now with the new betas (3 and 4) I have the issue that my functions do not get called anymore. It used to work with version 2. There are no logs on the server. I´m working on an example to reproduce that. Then I will see if 2) is really a schema error as you assume and I could finally use EmbeddedDocuments in my app.