public function asModel($class, $options = [])
    {
        $m = $this->newInstance($class, $options);

        foreach ($this->data as $field=> $value) {
            if ($value !== null && $value !== $this->getField($field)->default) {

                // Copying only non-default value
                $m[$field] = $value;
            }
        }

        // next we need to go over fields to see if any system
        // values have changed and mark them as dirty

        return $m;
    }
public function asModel($class, $options = [])
    {
        $m = $this->newInstance($class, $options);

        foreach ($this->data as $field=> $value) {
            if ($value !== null && $value !== $this->getField($field)->default) {

                // Copying only non-default value
                $m[$field] = $value;
            }
        }

        // next we need to go over fields to see if any system
        // values have changed and mark them as dirty

        return $m;
    }
public function asModel ( $ class , $ options = [ ] ) { $ m = $ this -> newInstance ( $ class , $ options ) ; foreach ( $ this -> data as $ field => $ value ) { if ( $ value !== null && $ value !== $ this -> getField ( $ field ) -> default ) { // Copying only non-default value $ m [ $ field ] = $ value ; } } // next we need to go over fields to see if any system // values have changed and mark them as dirty return $ m ; }
This will cast Model into another class without
loosing state of your active record.

@param string|Model $class
@param array        $options

@return Model
This will cast Model into another class without loosing state of your active record .