original_string: 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;
      }
code: 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;
      }
code_tokens: 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 ; }
docstring: Attach document to Norm system as model.
  
  @param mixed document Raw document data
  
  @return Norm\Model Attached model
docstring_tokens: Attach document to Norm system as model .