Search in sources :

Example 1 with PrimaryKeyMix

use of io.realm.entities.PrimaryKeyMix in project realm-java by realm.

the class RealmTests method copyToRealmOrUpdate_primaryKeyMixInObjectGraph.

@Test
public void copyToRealmOrUpdate_primaryKeyMixInObjectGraph() {
    // Crate Object graph where tier 2 consists of 1 object with primary key and one doesn't.
    // Tier 3 both have objects with primary keys.
    // 
    // PK
    // /      \
    // PK      nonPK
    // |        |
    // PK       PK
    DogPrimaryKey dog = new DogPrimaryKey(1, "Dog");
    OwnerPrimaryKey owner = new OwnerPrimaryKey(1, "Owner");
    owner.setDog(dog);
    Cat cat = new Cat();
    cat.setScaredOfDog(dog);
    PrimaryKeyMix mixObject = new PrimaryKeyMix(1);
    mixObject.setDogOwner(owner);
    mixObject.setCat(cat);
    realm.beginTransaction();
    PrimaryKeyMix realmObject = realm.copyToRealmOrUpdate(mixObject);
    realm.commitTransaction();
    assertEquals("Dog", realmObject.getCat().getScaredOfDog().getName());
    assertEquals("Dog", realmObject.getDogOwner().getDog().getName());
}
Also used : DogPrimaryKey(io.realm.entities.DogPrimaryKey) PrimaryKeyMix(io.realm.entities.PrimaryKeyMix) Cat(io.realm.entities.Cat) OwnerPrimaryKey(io.realm.entities.OwnerPrimaryKey) Test(org.junit.Test) UiThreadTest(androidx.test.annotation.UiThreadTest)

Aggregations

UiThreadTest (androidx.test.annotation.UiThreadTest)1 Cat (io.realm.entities.Cat)1 DogPrimaryKey (io.realm.entities.DogPrimaryKey)1 OwnerPrimaryKey (io.realm.entities.OwnerPrimaryKey)1 PrimaryKeyMix (io.realm.entities.PrimaryKeyMix)1 Test (org.junit.Test)1