String qualifierKey = keyValueQualifier.key();
String relationshipName = qualifierKey;
if (relationshipName.contains(".")) {
relationshipName = ERXStringUtilities.firstPropertyKeyInKeyPath(relationshipName);
}
EORelationship mergeRelationship = entity.relationshipNamed(relationshipName);
if (mergeRelationship != null) {
mergeRelationships.add(mergeRelationship);
qualifier = ERXQ.replaceQualifierWithQualifier(qualifier, keyValueQualifier,
ERXQ.has(qualifierKey, new NSArray(keyValueQualifier.value())));
} else if (qualifierKey.equals(entity.primaryKeyAttributeNames().get(0))
&& keyValueQualifier.selector().name().equals("doesContain") && !(keyValueQualifier.value() instanceof NSArray)) {
// fix wrong schemaBasedQualifier
qualifier= ERXQ.replaceQualifierWithQualifier(qualifier, keyValueQualifier,
ERXQ.is(qualifierKey, keyValueQualifier.value()));
}
}
}
// int count = 0;
NSMutableArray<NSMutableDictionary<String, Object>> fetchedRows = new NSMutableArray<NSMutableDictionary<String, Object>>();
Iterator<NSMutableDictionary<String, Object>> i = iterator();
while (i.hasNext()) {
NSMutableDictionary<String, Object> rawRow = i.next();
NSMutableDictionary<String, Object> row = rowFromStoredValues(rawRow, entity);
for (EORelationship mergeRelationship : mergeRelationships) {
NSArray<NSMutableDictionary<String, Object>> found = null;
if (mergeRelationship.isFlattened() && mergeRelationship.isToMany()) {
found = fetchRelatedManyToManyRows(entity, row, mergeRelationship, context);
} else {
found = fetchRelatedRows(entity, row, mergeRelationship, context);
}
if (found != null && !found.isEmpty()) {
row.setObjectForKey(found, mergeRelationship.name());
}
}
if (qualifier == null || qualifier.evaluateWithObject(row)) {
for (EORelationship mergeRelationship : mergeRelationships) {
row.removeObjectForKey(mergeRelationship.name());
}
fetchedRows.addObject(row);
// count++;
}
// if (fetchLimit > 0 && count == fetchLimit) {