public function save($options = array())
    {

        if ($this->isEmbed()) {
            return false;
        }

        $this->processReferencesChanged();
        $this->processEmbedsChanged();

        /* if no changes then do nothing */

        if ($this->_exist && empty($this->dirtyData) && empty($this->unsetData)) return true;

        $this->__preSave();

        if ($this->_exist) {
            $this->__preUpdate();
            $updateQuery = array();

            if (!empty($this->dirtyData)) {
                $updateQuery['$set'] = self::mapFields($this->dirtyData);
            };

            if (!empty($this->unsetData)) {
                $updateQuery['$unset'] = self::mapFields($this->unsetData);
            }

            $success = $this->_connection->update($this->collectionName(), array('_id' => $this->getId()), $updateQuery, $options);
            $this->__postUpdate();

        } else {
            $this->__preInsert();
            $data = self::mapFields($this->cleanData);
            $insert = $this->_connection->insert($this->collectionName(), $data, $options);
            $success = !is_null($this->cleanData['_id'] = $insert['_id']);
            if ($success) {
                $this->_exist = true ;
                $this->__postInsert();
            }

        }

        $this->dirtyData = array();
        $this->unsetData = array();
        $this->__postSave();

        return $success;

    }
public function save($options = array())
    {

        if ($this->isEmbed()) {
            return false;
        }

        $this->processReferencesChanged();
        $this->processEmbedsChanged();

        /* if no changes then do nothing */

        if ($this->_exist && empty($this->dirtyData) && empty($this->unsetData)) return true;

        $this->__preSave();

        if ($this->_exist) {
            $this->__preUpdate();
            $updateQuery = array();

            if (!empty($this->dirtyData)) {
                $updateQuery['$set'] = self::mapFields($this->dirtyData);
            };

            if (!empty($this->unsetData)) {
                $updateQuery['$unset'] = self::mapFields($this->unsetData);
            }

            $success = $this->_connection->update($this->collectionName(), array('_id' => $this->getId()), $updateQuery, $options);
            $this->__postUpdate();

        } else {
            $this->__preInsert();
            $data = self::mapFields($this->cleanData);
            $insert = $this->_connection->insert($this->collectionName(), $data, $options);
            $success = !is_null($this->cleanData['_id'] = $insert['_id']);
            if ($success) {
                $this->_exist = true ;
                $this->__postInsert();
            }

        }

        $this->dirtyData = array();
        $this->unsetData = array();
        $this->__postSave();

        return $success;

    }
public function save ( $ options = array ( ) ) { if ( $ this -> isEmbed ( ) ) { return false ; } $ this -> processReferencesChanged ( ) ; $ this -> processEmbedsChanged ( ) ; /* if no changes then do nothing */ if ( $ this -> _exist && empty ( $ this -> dirtyData ) && empty ( $ this -> unsetData ) ) return true ; $ this -> __preSave ( ) ; if ( $ this -> _exist ) { $ this -> __preUpdate ( ) ; $ updateQuery = array ( ) ; if ( ! empty ( $ this -> dirtyData ) ) { $ updateQuery [ '$set' ] = self :: mapFields ( $ this -> dirtyData ) ; } ; if ( ! empty ( $ this -> unsetData ) ) { $ updateQuery [ '$unset' ] = self :: mapFields ( $ this -> unsetData ) ; } $ success = $ this -> _connection -> update ( $ this -> collectionName ( ) , array ( '_id' => $ this -> getId ( ) ) , $ updateQuery , $ options ) ; $ this -> __postUpdate ( ) ; } else { $ this -> __preInsert ( ) ; $ data = self :: mapFields ( $ this -> cleanData ) ; $ insert = $ this -> _connection -> insert ( $ this -> collectionName ( ) , $ data , $ options ) ; $ success = ! is_null ( $ this -> cleanData [ '_id' ] = $ insert [ '_id' ] ) ; if ( $ success ) { $ this -> _exist = true ; $ this -> __postInsert ( ) ; } } $ this -> dirtyData = array ( ) ; $ this -> unsetData = array ( ) ; $ this -> __postSave ( ) ; return $ success ; }
Save to database

@param array $options options

@return array
Save to database