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

Throwing C-API when creating object with duplicate primary key

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

      In the current implementation of the C-API the`realm_object_create_with_primary_key`-function acts as a find or create and will return the existing object if one already existed.

      In Kotlin we would like to throw an error if the user tries to create objects with duplicate primary keys, similarly to other SDKs (Java, Cocoa).

      I think it would be most consistent if the `realm_object_create_with_primary_key` would raise an error (through returning a null pointer and checking the `last_error`) and introduce a new call for the upsert variant. This way the `RLM_ERR_DUPLICATE_PRIMARY_KEY_VALUE` error value could be used consistently when ever the unique constraint was violated across the API.

            Assignee:
            jorgen.edelbo@mongodb.com Jørgen Edelbo
            Reporter:
            claus.rorbech@mongodb.com Claus Rørbech (Inactive)
            Votes:
            0 Vote for this issue
            Watchers:
            2 Start watching this issue

              Created:
              Updated:
              Resolved: