protected function _relationCast($field, $name, $data, $options)
    {
        $options = $this->_relations[$name] + $options;
        $options['basePath'] = $options['embedded'] ? $name : null;
        $options['schema'] = $options['embedded'] ? $this : null;

        if ($options['relation'] !== 'hasManyThrough') {
            $options['class'] = $options['to'];
        } else {
            $through = $this->relation($name);
            $options['class'] = $through->to();
        }
        if ($field) {
            return $options['array'] ? $this->_castArray($name, $data, $options) : $this->_cast($name, $data, $options);
        }
        if (!isset($this->_columns[$name])) {
            return $data;
        }
        $column = $this->_columns[$name];
        return $this->convert('cast', $column['type'], $data, $column, $options);
    }