EmbeddedObject with LinkingObjects

Before going too far with this, does the Swift SDK support using EmbeddedObjects with LinkingObjects?

Here’s the use case

suppose we have a person class with a List of embedded addresses

class PersonClass: Object {
   var addressList = List<EmbeddedAddress>()

and then the EmbeddedAddress looks like this

class EmbeddedAddress: EmbeddedObject {
    @objc dynamic var address = ""
    @objc dynamic var linked_neighborhood: Neighborhood!

but then we also want to have a Neighborhood object that tracks back to those addresses

class Neighborhood: Object {
    @objc dynamic var name = ""
    let linkingAddresses = LinkingObjects(fromType: EmbeddedAddress.self, property: "linked_neighborhood")

with this setup we can retrieve a neighborhood from Realm and then show all of the addresses

let hood = realm.objects(Neighborhood.self)....filter for some neighborhood
for addr in hood.linkingAddresses {

This seems to be working but… is it supposed to be since EmbeddedObjects are not officially Managed Objects?

The issue we are running into which prompted the question actually ties back to a problem discovered previously where when working with an object with embedded objects, if you want to create an unmanaged copy of an object that has embedded objects, you need to make a deep copy of the embedded objects.

While it seems unrelated, it is. More info to follow.

Looping back around to the original question

Is using an EmbeddedObject as a Linking object a thing?

Would appreciate any input from a Realmer here - just want know if that’s something that is working by design or if it just accidentally works and will be removed in a future release.

Hi @Jay, sorry for the delay. I posted a question around this to one of our internal developer lists and wanted to give a bit of time for people to raise a red flag.

It feels it’s something that isn’t not supported, but it isn’t the typical use of the feature and so there’s always a risk that you hit a bug that isn’t covered by our testing.

Sorry for the less than definitive answer!

1 Like


Thanks so much for reaching out to your team and providing an update.

We are trying to leverage EmbeddedObjects in situations where data needs a ‘format’ and ties to a single object so yet-another managed is object is not needed; like a persons address as in my initial example.

In the future, I hope we can get a little more clear definition of the functionality, along with some eyeballs on creating an unmanaged version of the EmbeddedObject as well.

1 Like