public function setModel($model, $actual_fields = null)
    {
        parent::setModel($model);

        if ($this->model instanceof \atk4\data\Model) {
            // Switch to Agile Data implementation
            if (isset($this->default_controller)) {
                $this->default_controller = str_replace('MVC', 'AD', $this->default_controller);
            } else {
                $this->default_controller = 'ADView';
            }
        }

        // Some models will want default controller to be associated
        if (isset($this->model->default_controller)) {
            $this->controller
                = $this->model->setController($this->model->default_controller);
        }

        // Use our default controller if present
        if ($this->default_controller) {
            $this->controller = $this->setController($this->default_controller);
        }

        if ($this->controller) {
            if ($this->controller->hasMethod('setActualFields')) {
                $this->controller->setActualFields($actual_fields);
            }
            if ($this->controller->hasMethod('_bindView')) {
                $this->controller->_bindView();
            }
        }

        if ($this->model instanceof SQL_Model) {
            $this->dq = $this->model->_dsql();    // compatibility
        }

        $this->hook('set-model', [$this->model, $actual_fields]);

        return $this->model;
    }