Last active
August 29, 2015 14:21
-
-
Save Gryzor/89d4d92b0342c49ab78e to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// getter/setter ommited | |
class A extends RealmObject { | |
@PrimaryKey | |
private String name; | |
} | |
class B extends RealmObject { | |
@PrimaryKey | |
private String name; | |
private A a; | |
} | |
void do() { | |
A a = new A(); | |
a.setName("a"); | |
B b = new B(); | |
b.setName("b"); | |
b.setOne(a); | |
B c = new B(); | |
c.setName("c"); | |
c.setOne(a); | |
realm = Realm.getInstance(…); | |
realm.beginTransaction(); | |
realm.copyToRealm(b); | |
realm.copyToRealm(c); | |
realm.commitTransaction(); | |
realm.close(); | |
} | |
// if we use copyToRealmOrUpdate(), doesn't this cause the 'c' object to UPDATE the existing 'a' (inserted by 'b')? | |
// If we don't, we get a PK violation |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment