public function attach($document)
    {
        if (isset($this->connection)) {
            $document = $this->connection->unmarshall($document);
        }

        // wrap document as NObject instance to make sure it can be override by hooks
        $document = new NObject($document);

        $this->applyHook('attaching', $document);

        if (isset($this->options['model'])) {
            $Model = $this->options['model'];
            $model = new $Model($document->toArray(), array(
                'collection' => $this,
            ));
        } else {
            $model = new Model($document->toArray(), array(
                'collection' => $this,
            ));
        }

        $this->applyHook('attached', $model);

        return $model;
    }