/**
  *
  * Gets all the related entities (or if its a belongs-to relation just the one)
  * to the item with the given id
  *
  * @param \WP_REST_Request $request
  * @return \WP_REST_Response|\WP_Error
  */
 public static function handle_request_get_related(\WP_REST_Request $request)
 {
     $controller = new Read();
     try {
         $matches = $controller->parse_route($request->get_route(), '~' . \EED_Core_Rest_Api::ee_api_namespace_for_regex . '(.*)/(.*)/(.*)~', array('version', 'model', 'id', 'related_model'));
         $controller->set_requested_version($matches['version']);
         $main_model_name_singular = \EEH_Inflector::singularize_and_upper($matches['model']);
         if (!$controller->get_model_version_info()->is_model_name_in_this_version($main_model_name_singular)) {
             return $controller->send_response(new \WP_Error('endpoint_parsing_error', sprintf(__('There is no model for endpoint %s. Please contact event espresso support', 'event_espresso'), $main_model_name_singular)));
         }
         $main_model = $controller->get_model_version_info()->load_model($main_model_name_singular);
         //assume the related model name is plural and try to find the model's name
         $related_model_name_singular = \EEH_Inflector::singularize_and_upper($matches['related_model']);
         if (!$controller->get_model_version_info()->is_model_name_in_this_version($related_model_name_singular)) {
             //so the word didn't singularize well. Maybe that's just because it's a singular word?
             $related_model_name_singular = \EEH_Inflector::humanize($matches['related_model']);
         }
         if (!$controller->get_model_version_info()->is_model_name_in_this_version($related_model_name_singular)) {
             return $controller->send_response(new \WP_Error('endpoint_parsing_error', sprintf(__('There is no model for endpoint %s. Please contact event espresso support', 'event_espresso'), $related_model_name_singular)));
         }
         return $controller->send_response($controller->get_entities_from_relation($request->get_param('id'), $main_model->related_settings_for($related_model_name_singular), $request));
     } catch (\Exception $e) {
         return $controller->send_response($e);
     }
 }
 /**
  * Removes the "_calculate_fields" part of entity responses before 4.8.36
  * @param array $entity_response_array
  * @param \EEM_Base $model
  * @param string $request_context
  * @param \WP_REST_Request $request
  * @param Read $controller
  * @return array
  */
 public function remove_old_featured_image_part_of_cpt_entities($entity_response_array, \EEM_Base $model, $request_context, \WP_REST_Request $request, Read $controller)
 {
     if ($this->applies_to_version($controller->get_model_version_info()->requested_version()) && $model instanceof \EEM_CPT_Base) {
         $attachment = wp_get_attachment_image_src(get_post_thumbnail_id($entity_response_array[$model->primary_key_name()]), 'full');
         $entity_response_array['featured_image_url'] = !empty($attachment) ? $attachment[0] : null;
     }
     return $entity_response_array;
 }