Uploaded image for project: 'Realm Cocoa SDK'
  1. Realm Cocoa SDK
  2. RCOCOA-1168

Using Multiple @ObervedResult with different realm configurations

    • Type: Icon: Improvement Improvement
    • Resolution: Fixed
    • Priority: Icon: Major - P3 Major - P3
    • None
    • Affects Version/s: None
    • Component/s: None

      Hi guys!

      It's good idea is hiding whole crud logic under the hood of property wrappers.

      I have faced with issue where I what to use couple of entities which have different realms in single View and I got the app termination because EnvironmentValue is providing an only one realm configuration.

      https://github.com/realm/realm-cocoa/blob/f0af9a11038c44d0de3aac11ba6b7e27d7432660/RealmSwift/SwiftUI.swift#L266

      I saw in the code example above this constructor:

      @ObservedObject(UserData.self, configuration: ....) 
      

      Why it doesn't work? It's so really handy - providing particular configuration as I want.

      At the time I have:

      @ObservedResults(Account.self) var accounts // use .environment(\.realmConfiguration) implicitly and working properly
      @ObservedResults(
           UserPublicData.self, 
           configuration: RealmApp.createConfiguration(user: RealmApp.default.realmUser!, partition: "shared")
      ) var userPublicData // doesn't work
      

      and it is dropping with:

      *** Terminating app due to uncaught exception 'RLMException', 
      reason: 'Object type 'UserPublicData' is not managed by the Realm. 
      If using a custom `objectClasses` / `objectTypes` array in your configuration, add `UserPublicData` to the list of `objectClasses` / `objectTypes`.'
      

      static method of RealmApp:

      static func createConfiguration(user:RealmSwift.User, partition: String) -> Realm.Configuration {
          var configuration = user.configuration(partitionValue: partition)
          let partitionKey = String(partition.split(separator: "=")[0])
      
          if partitionKey == "account" {
              configuration.objectTypes = accountObjectTypes
          } else if partitionKey == "shared" {
      	configuration.objectTypes = [UserPublicData.self]
          }
          return configuration
      }
      

      PS:
      Guys, please do something with realm configurations. I what to provide bunch of partition values to retrieve shared entities from any partitions as if it's just one.

            Assignee:
            jason.flax@mongodb.com Jason Flax
            Reporter:
            unitosyncbot Unito Sync Bot
            Votes:
            0 Vote for this issue
            Watchers:
            1 Start watching this issue

              Created:
              Updated:
              Resolved: