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

Ensure Migration.enumerateObjects(ofType:_:) consistently uses property mappings

      Problem

      When performing a Migration.enumerateObjects(ofType:_, within the executed block (MigrationObjectEnumerateBlock) the old object and new object inconsistently use the property mappings for the given object.

      Suppose the example snippet below:

      class Example: Object {
          // ...
          @Persisted var someField: String = "default value"
          // ...
      
          override class public func propertiesMapping() -> [String : String] {
              [
                  "someField": "some_field"
              ]
          }
      }
      

      Inside of a migration, when running enumerateObjects(ofType:_, I observe the following behaviour within the MigrationObjectEnumerateBlock:

      • The new object can only access Example.someField by using newObject["someField"]
      • The old object can only access Example.someField by using oldObject["some_field"].

      I understand this is probably to do with something under the hood when Realm actually maps the properties, and that changing this might be not worth the difficulty.

      Even if this is decided to be the intended behaviour, this should be documented as I had to work this out through trial and error.

      Solution

      No response

      Alternatives

      No response

      How important is this improvement for you?

      I would like to have it but have a workaround

      Feature would mainly be used with

      Local Database only

            Assignee:
            Unassigned Unassigned
            Reporter:
            unitosyncbot Unito Sync Bot
            Votes:
            0 Vote for this issue
            Watchers:
            2 Start watching this issue

              Created:
              Updated: