public static function fromModel(Model $model, $excludeRels = false)
    {
        $fields = [];

        /** @var $field Field */
        foreach ($model->getMeta()->localFields as $name => $field) {
            try {
                $fields[$name] = $field->deepClone();
            } catch (\Exception $e) {
                throw new TypeError(
                    sprintf(
                        "Couldn't reconstruct field %s on %s: %s",
                        $name,
                        $model->getMeta()->getNSModelName()
                    )
                );
            }
        }

        if (false == $excludeRels) {
            foreach ($model->getMeta()->localManyToMany as $name => $field) {
                try {
                    $fields[$name] = $field->deepClone();
                } catch (\Exception $e) {
                    throw new TypeError(
                        sprintf(
                            "Couldn't reconstruct field %s on %s: %s",
                            $name,
                            $model->getMeta()->getNSModelName()
                        )
                    );
                }
            }
        }

        $overrides = $model->getMeta()->getOverrides();
        $meta = [];
        $ignore = ['registry'];
        foreach ($overrides as $name => $value) {
            if (in_array($name, $ignore)) {
                continue;
            }
            $meta[$name] = $value;
        }

        $extends = '';

        /** @var $immediateParent ReflectionObject */
        list($concreteParent, $immediateParent) = Model::getHierarchyMeta($model);

        if ($immediateParent) {
            if ($immediateParent->isAbstract()) {
                $extends = (is_null($concreteParent)) ? '' : $concreteParent;
            } else {
                $extends = $immediateParent->getName();
            }
        }

        $kwargs = [
            'meta' => $meta,
            'extends' => $extends,
        ];

        return new static($model->getMeta()->getNSModelName(), $fields, $kwargs);
    }