Flexible Sync Across Relationships

Does flexible sync pull objects across relationships like Lists, LinkingObjects, or direct relationships? Assuming this basic schema:

class Person: Object {
    @Persisted(primaryKey: true) var _id = UUID().uuidString

    @Persisted var shirts: List<Shirt>

    @Persisted(originProperty: "owner") var pants: LinkingObjects<Pants>
}

class Pants: Object {
    @Persisted(primaryKey: true) var _id = UUID().uuidString

    @Persisted var owner: Person?
}

class Shirt: Object {
    @Persisted(primaryKey: true) var _id = UUID().uuidString
}

Would this query sync Pants and Shirts?

try await subscriptions.update {
    let sub = QuerySubscription<Person>(name: "subscription")
        subscriptions.append(sub)
    }

Would this query sync Persons?

try await subscriptions.update {
    let sub = QuerySubscription<Pants>(name: "subscription")
        subscriptions.append(sub)
    }
1 Like

Hey @Harry_Netzer1 - Flexible Sync does not pull in linked objects. You’d need to add subscriptions for the linked objects you need to preserve the relationships. In your examples, querying for Person does not sync Pants and Shirts, and querying for Pants does not sync Person/Shirt. If you subscribe to all three object types, the links/relationships will function as expected.

2 Likes

Thanks for clearing that up. I’ll use something like a region Id on all my objects.

In the old days, sync pulled in directly referenced objects and could be configured to pull linkingObjects too. Any chance of this feature in the future?

I’m not sure what form it will take, but I think @Ian_Ward and the engineering team has some plans for linked object support. Stay tuned!