EOEntity joinEntity = toJoinRelationship.destinationEntity();
EREntityStore joinStore = context._entityStoreForEntity(joinEntity);
String sourceAttribute = toJoinRelationship.sourceAttributes().get(0).name();
String destinationAttribute = toJoinRelationship.destinationAttributes().get(0).name();
ERXFetchSpecification fs = new ERXFetchSpecification(joinEntity.name(), ERXQ.equals(destinationAttribute,
row.valueForKey(sourceAttribute)), null);
NSArray<NSMutableDictionary<String, Object>> fetchedObjects = joinStore.fetch(joinEntity.attributesToFetch(),
fs, false, joinEntity, context);
if (fetchedObjects.isEmpty()) {
return NSArray.EmptyArray;
}
EORelationship destRelationship = joinEntity.anyRelationshipNamed(toDestKey);
sourceAttribute = destRelationship.sourceAttributes().get(0).name();
destinationAttribute = destRelationship.destinationAttributes().get(0).name();
NSArray<Object> destValues = (NSArray<Object>) fetchedObjects.valueForKey(sourceAttribute);
EOEntity destEntity = relationship.destinationEntity();
fs = new ERXFetchSpecification(destEntity.name(), ERXQ.in(destinationAttribute, destValues), null);
EREntityStore destinationStore = context._entityStoreForEntity(destEntity);
fetchedObjects = destinationStore.fetch(destEntity.attributesToFetch(), fs, false, destEntity, context);
return fetchedObjects;
}