Uploaded image for project: 'Realm Core'
  1. Realm Core
  2. RCORE-1775

Allow asymmetric objects to contain links to non-embedded objects

    • Type: Icon: Improvement Improvement
    • Resolution: Fixed
    • Priority: Icon: Minor - P4 Minor - P4
    • None
    • Affects Version/s: None
    • Component/s: None
    • None

      Currently having links to regular realm objects is not allowed in asymmetric objects. Trying to define a realm model like this

      Unable to find source-code formatter for language: dart. Available languages are: actionscript, ada, applescript, bash, c, c#, c++, cpp, css, erlang, go, groovy, haskell, html, java, javascript, js, json, lua, none, nyan, objc, perl, php, python, r, rainbow, ruby, scala, sh, sql, swift, visualbasic, xml, yaml
      @RealmModel(ObjectType.asymmetricObject)
      class _Asymmetric {
        _Symmetric? symmetric;
        // ...
      }
      
      @RealmModel()
      class _Symmetric {
        // ...
      }
      

      is disallowed by realm-core. Opening a realm with such schema will throw:

        RealmException: Error opening realm at path <redacted>. Error code: 2016 . Message: Schema validation failed due to the following errors:
        - Asymmetric table with property 'Asymmetric.symmetric' of type 'object' cannot have a non-embedded object type.
      

      But it is trivial to work-around this restriction by injecting an embedded object like this:

      Unable to find source-code formatter for language: dart. Available languages are: actionscript, ada, applescript, bash, c, c#, c++, cpp, css, erlang, go, groovy, haskell, html, java, javascript, js, json, lua, none, nyan, objc, perl, php, python, r, rainbow, ruby, scala, sh, sql, swift, visualbasic, xml, yaml
      @RealmModel(ObjectType.asymmetricObject)
      class _Asymmetric {
        late List<_Embedded> embeddedObjects;
        // ...
      }
      
      @RealmModel(ObjectType.embeddedObject)
      class _Embedded {
        late RealmValue any;
        _Symmetric? symmetric;
      }
      
      @RealmModel()
      class _Symmetric {
        // ...
      }
      

      From discussion with BAAS team they don't have any problems with supporting links to non-embedded objects, so I request we lift the restriction in realm-core as well, since it is not really enforced anyway.

            Assignee:
            kasper.nielsen@mongodb.com Kasper Nielsen
            Reporter:
            kasper.nielsen@mongodb.com Kasper Nielsen
            AD Core
            Votes:
            0 Vote for this issue
            Watchers:
            1 Start watching this issue

              Created:
              Updated:
              Resolved: