public function saveVersion(ModelInterface $model, $username)
    {
        $queryBuilder = $this->connection->createQueryBuilder();
        $queryBuilder->select('COUNT(*) AS count');
        $queryBuilder->from('tl_version');
        $queryBuilder->andWhere($queryBuilder->expr()->eq('tl_version.pid', ':pid'));
        $queryBuilder->setParameter(':pid', $model->getId());
        $queryBuilder->andWhere($queryBuilder->expr()->eq('tl_version.fromTable', ':fromTable'));
        $queryBuilder->setParameter(':fromTable', $this->source);

        $statement = $queryBuilder->execute();
        $count     = $statement->fetch(\PDO::FETCH_COLUMN);

        $mixNewVersion = ((int) $count + 1);
        $mixData       = $model->getPropertiesAsArray();

        $mixData[$this->idProperty] = $model->getId();

        $insert = [
            'tl_version.pid'       => $model->getId(),
            'tl_version.tstamp'    => \time(),
            'tl_version.version'   => $mixNewVersion,
            'tl_version.fromTable' => $this->source,
            'tl_version.username'  => $username,
            'tl_version.data'      => \serialize($mixData)
        ];

        $this->connection->insert('tl_version', $insert);

        $this->setVersionActive($model->getId(), $mixNewVersion);
    }