We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
It is currently not possible with RealmList to add multiple items with the same primary key (or for different lists to add an item with the same primary key) RealmListInternal uses UpdatePolicy.ERROR for its insert operators (https://github.com/realm/realm-kotlin/blob/master/packages/library-base/src/commonMain/kotlin/io/realm/internal/RealmListInternal.kt#L197) which differs from the behaviour in realm-java (which uses copyToRealmOrUpdate when adding unmanaged objects to a managed RealmList https://github.com/realm/realm-java/blob/master/realm/realm-library/src/main/java/io/realm/RealmList.java#L214)
class TestList: RealmObject { var items: RealmList<TestItem> = realmListOf() } class TestItem : RealmObject { @PrimaryKey var id: String = "1" }
realm.write { val myList = copyToRealm(TestList()) myList.items.add(TestItem()) myList.items.add(TestItem()) }
realm.write { val testList1 = copyToRealm(TestList()) val testList2 = copyToRealm(TestList()) testList1.items.add(TestItem()) testList2.items.add(TestItem()) }
java.lang.IllegalArgumentException: Failed to create object of type 'TestItem': RealmCoreException([33]: Object with this primary key already exists)
The text was updated successfully, but these errors were encountered:
Hi @t7costa Thank you for this. You are correct, we should have the same semantics as Realm Java. We will fix this.
Sorry, something went wrong.
rorbech
Successfully merging a pull request may close this issue.
It is currently not possible with RealmList to add multiple items with the same primary key (or for different lists to add an item with the same primary key)
RealmListInternal uses UpdatePolicy.ERROR for its insert operators (https://github.com/realm/realm-kotlin/blob/master/packages/library-base/src/commonMain/kotlin/io/realm/internal/RealmListInternal.kt#L197) which differs from the behaviour in realm-java (which uses copyToRealmOrUpdate when adding unmanaged objects to a managed RealmList https://github.com/realm/realm-java/blob/master/realm/realm-library/src/main/java/io/realm/RealmList.java#L214)
java.lang.IllegalArgumentException: Failed to create object of type 'TestItem': RealmCoreException([33]: Object with this primary key already exists)
The text was updated successfully, but these errors were encountered: