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);
    }
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);
    }
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 ) ; }
Casting helper for relations.

@param  string $field      The field name to cast.
@param  string $name       The full field name to cast.
@param  array  $data       Some data to cast.
@param  array  $options    Options for the casting.
@return mixed              The casted data.
Casting helper for relations .