+ object.storedValueForKey(relationshipName).getClass().getName(), e);
}
final EOEditingContext ec = object.editingContext();
EOEntity entity = ERXEOAccessUtilities.entityForEo(object);
EORelationship relationship = entity.relationshipNamed(relationshipName);
// Fail in the event that the relationship fault is not a toMany
if (!relationship.isToMany()) {
// Happens if toOne key used and the to-one is a fault
throw new IllegalArgumentException("The attribute named '" + relationshipName
+ "' in the entity named '" + object.entityName() +"' is not a toMany relationship!");
}
// --- (3) Case of a fault and a snapshot exists to provide a count
final EOGlobalID gid = ec.globalIDForObject(object);
String modelName = entity.model().name();
final EODatabaseContext dbc = EOUtilities.databaseContextForModelNamed(ec, modelName);
NSArray toManySnapshot = ERXEOAccessUtilities.executeDatabaseContextOperation(dbc, 2,
new DatabaseContextOperation<NSArray>() {
public NSArray execute(EODatabaseContext databaseContext) throws Exception {
// Search for and return the snapshot
return dbc.snapshotForSourceGlobalID(gid, relationshipName, ec.fetchTimestamp());
}
});
// Null means that a relationship snapshot array was not found in EODBCtx or EODB.
if (toManySnapshot != null) {
// --- (3) return result
return Integer.valueOf(toManySnapshot.count());
}
// Default case
// --- (4) Case where relationship has not been faulted, and no snapshot array exists
EOQualifier q = EODatabaseDataSource._qualifierForRelationshipKey(relationshipName, object);
// --- (4) return result
return objectCountWithQualifier(ec, relationship.destinationEntity().name(), q);
}