ObjectContext clientContext = getClientContext();
DefaultsTable4 o = (DefaultsTable4) DataObjectUtils.objectForPK(
clientContext, DefaultsTable4.class, Collections.singletonMap(
"id", 1));
DefaultsTable3 o1 = (DefaultsTable3) DataObjectUtils.objectForPK(
clientContext, DefaultsTable3.class, Collections.singletonMap(
"id", 1));
DefaultsTable3 o2 = (DefaultsTable3) DataObjectUtils.objectForPK(
clientContext, DefaultsTable3.class, Collections.singletonMap(
"id", 2));
assertEquals(1, o1.getDefaultTable4s().size());
assertEquals(0, o2.getDefaultTable4s().size());
o2.addToDefaultTable4s(o);
assertEquals(1, o2.getDefaultTable4s().size());
assertFalse(clientContext.modifiedObjects().isEmpty());
clientContext.commitChanges();
assertEquals(1, o2.getDefaultTable4s().size());
// there is a bug in RefreshQuery that fails to invalidate to-many on
// the client - so working around it be creating a new context; still
// running the query though to refresh the server
clientContext.performQuery(new RefreshQuery());