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;
    }
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;
    }
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 ; }
Attach document to Norm system as model.

@param mixed document Raw document data

@return Norm\Model Attached model
Attach document to Norm system as model .