I did find that the technique did not work for to-many relationships, but added a bit of code towards the end of the method to refresh the to-many relationships using Wonder:
/**
* Core method to refresh properties selectively with data from the database. The
* properties can be attributes, to-one or to-many relationships.
*/
public void refreshProperties(NSArray<String> keys) {
NSDictionary<String, Object> changes = changesFromCommittedSnapshot();
// Discard changes to the properties that we're about to refresh if any
NSMutableDictionary<String, Object> changesToKeepAfterRefresh = changes.mutableClone();
changesToKeepAfterRefresh.removeObjectsForKeys(keys);
// Now fetch the receiver refreshing it with changes from database
EOEntity entity = entity();
EOFetchSpecification fs = new EOFetchSpecification(entity.name(), primaryKeyQualifier(), null);
fs.setRefreshesRefetchedObjects(true);
editingContext().objectsWithFetchSpecification(fs);
// Now re-apply the changes we want to keep
if (changesToKeepAfterRefresh.count() > 0) {
takeValuesFromDictionary(changesToKeepAfterRefresh);
}
// The above will not refresh to-many relationships so do something a bit
// more drastic to refresh the to-many relationships.
for (String key : keys) {
EORelationship relationship = entity.relationshipNamed(key);
if (relationship.isToMany()) {
ERXEOControlUtilities.clearSnapshotForRelationshipNamed(this, key);
}
}
}
/**
* Convenience method to refresh properties selectively with data from the database.
* The properties can be attributes, to-one or to-many relationships.
*/
public void refreshProperties(String... keys) {
NSArray<String> keysArray = new NSArray<String>(keys);
refreshProperties(keysArray);
}
/**
* Convenience method to refresh properties selectively with data from the database.
* The properties can be attributes, to-one or to-many relationships.
*/
public void refreshProperties(ERXKey<?>... erxKeys) {
NSMutableArray<String> keys = new NSMutableArray<String>(erxKeys.length);
for (ERXKey<?> erxKey : erxKeys) {
keys.add(erxKey.key());
}
refreshProperties(keys);
}