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());
}
Aggregations