EOEntity entity = modelGroup.entityNamed(entityName);
EOAttribute selectedAttribute = null;
if (relationshipKey() != null && entity.relationshipNamed(relationshipKey()) != null) {
EORelationship relationship = entity.relationshipNamed(relationshipKey());
EOEntity destinationEntity = relationship.destinationEntity();
selectedAttribute = destinationEntity.attributeNamed(key);
} else {
selectedAttribute = entity.attributeNamed(key);
}
return selectedAttribute.className();
}