public function _name($from, $to, $action)
{
switch ($action) {
case static::ACT_CONVERT_TO_OBJECT:
/* @var $from Entity\FarmRoleScalingMetric */
$to->name = ScalingMetricAdapter::metricNameToData($from->metric->name);
break;
case static::ACT_CONVERT_TO_ENTITY:
$this->validateString($from->name, 'Property name contains invalid characters');
/* @var $metric Entity\ScalingMetric */
$metric = Entity\ScalingMetric::findOne([['name' => ScalingMetricAdapter::metricNameToEntity($from->name)]]);
if (empty($metric)) {
throw new ApiErrorException(404, ErrorMessage::ERR_OBJECT_NOT_FOUND, sprintf('Scaling metric with name %s does not exist', $from->name));
}
/* @var $to Entity\FarmRoleScalingMetric */
$to->metricId = $metric->id;
$to->metric = $metric;
break;
case static::ACT_GET_FILTER_CRITERIA:
return [[]];
}
}