protected function doInsert(array &$a, array $options = array())
    {
        // If there is no file, perform a basic insertion
        if ( ! isset($a['file'])) {
            parent::doInsert($a, $options);
            return;
        }

        /* If the file is dirty (i.e. it must be persisted), delegate to the
         * storeFile() method. Otherwise, perform a basic insertion.
         */
        $file = $a['file']; // instanceof GridFSFile
        unset($a['file']);

        if ($file->isDirty()) {
            $this->storeFile($file, $a, $options);
        } else {
            parent::doInsert($a, $options);
        }

        $a['file'] = $file;
        return $a;
    }