Saves or updates the current object instance depending on the presence of `object.id`.

 @example
   object.save

 @return [self] Returns the instance refreshed from the API.

 @since 0.1.0
430101
def save
      if @id
        resource = self.class::RESOURCE % { account_id: account.id, id: id }
        response = Request.new(account.client, :put, resource, params: to_params).perform
      else
        resource = self.class::RESOURCE_COLLECTION % { account_id: account.id }
        response = Request.new(account.client, :post, resource, params: to_params).perform
      end
      from_response(response.body[:data])
    end
886043
def save
      response = service.send(:"#{method_prefix}_update", self.attrs)

      if response.at_xpath('//status').attr('code') == 'ok'
        # Load the ID if this was a creation
        self.id = response.at_xpath("//#{ac_obj_node_name}").attr("#{ac_obj_type}-id") if self.id.nil?
        true
      else
        save_errors(response)
        false
      end
    end
163839
def save
      if loaded?
        self.class.update(@fields.format_for_update, jira_key)
      else
        response = self.class.create(@fields.format_for_create)
        self.jira_key = response.parsed_response["key"]
      end
      jira_key
    end
1239603
def reload
      raise Couchbase::Error::MissingId, 'missing id attribute' unless @id
      pristine = model.find(@id)
      update_attributes(pristine.attributes)
      @meta[:cas] = pristine.meta[:cas]
      self
    end
295398
def save(self, **kwargs):
        
        validated_data = [
            dict(list(attrs.items()) + list(kwargs.items()))
            for attrs in self.validated_data
        ]

        if "id" in validated_data:
            ModelClass = self.Meta.model

            try:
                self.instance = ModelClass.objects.get(id=validated_data["id"])
            except ModelClass.DoesNotExist:
                pass

        return super(VideohubVideoSerializer, self).save(**kwargs)
1184054
async def save(self):
        

        if hasattr(self, "before_save"):
            self.before_save()

        query = r.table(self.table_name)

        if self._state.get("id"):
            query = query \
                .get(self._state.get("id")) \
                .update(self.__db_repr, return_changes=True)
        else:
            query = query \
                .insert(self.__db_repr, return_changes=True)

        resp = await query.run(await conn.get())

        try:
            changes = resp["changes"]

            if len(changes) > 0:
                self.wrap(resp["changes"][0]["new_val"])
        except KeyError:
            raise UnexpectedDbResponse()

        if resp["skipped"] > 0:
            raise UnexpectedDbResponse(
                "Model with id `%s` not found in the database." %
                self._state.get("id"))

        return self
103680
def create(self, instance):
        
        with self.flushing():
            if instance.id is None:
                instance.id = self.new_object_id()
            self.session.add(instance)
        return instance
55974
def update(self, instance):
        
        assert isinstance(instance, self.model_klass)
        if instance.db_id:
            query = {'_id': ObjectId(instance.db_id)}
        else:
            query = build_db_query(self.primary_key, instance.key)
        self.ds.update(self.collection_name, query, instance)
        return instance.db_id
319164
function save()
    {
        if ($this->id != false || $this->id != 0) {
            return $this->update();
        } else {
            return $this->insert();
        }
    }
1324761
def save(element, changeset)
      response = if element.id.nil?
        create(element, changeset)
      else
        update(element, changeset)
      end
    end
86442
function(instance) {
      var loadData = function(data) {
        return _.extend(instance, data);
      };

      if (instance.id) {
        // do PUT save
        return api
          .one(config.entity, instance.id)
          .put(instance)
          .then(loadData, console.error);
      } else {
        // no id is set, do a POST
        var endpoint = api;
        if (config.parent) {
          endpoint.one(config.parent.entity, instance[config.parent.key]);
        }
        endpoint.all(config.entity);

        return endpoint
          .post(instance)
          .then(loadData, console.error);
      }
    }
902586
def save_modified_attributes!(opts={})
    options = { :validate => true }.merge(opts)
    if options[:validate]
      # Complain if we aren't valid
      raise InvalidRecord, @errors.full_messages.join(", ") unless valid?
    end
    # Send the save request
    response = self.class.session.connection.set_entry(self.class._module.name, serialize_modified_attributes)
    # Complain if we don't get a parseable response back
    raise RecordsaveFailed, "Failed to save record: #{self}.  Response was not a Hash" unless response.is_a? Hash
    # Complain if we don't get a valid id back
    raise RecordSaveFailed, "Failed to save record: #{self}.  Response did not contain a valid 'id'." if response["id"].nil?
    # Save the id to the record, if it's a new record
    @attributes[:id] = response["id"] if new?
    raise InvalidRecord, "Failed to update id for: #{self}." if id.nil?
    # Clear the modified attributes Hash
    @modified_attributes = {}
    true
  end
753327
def save_as_persisted_record
      new_attributes = attributes.reject { |k, _v| k.to_s =~ /^(id|uuid)$/ }
      self.class.update(id, new_attributes)
    end
1125949
def put_object(obj, id)
      find_blob(id, true).write_object(id, serialize(obj))
    end
933375
def save(self):
        
        if 'save' not in self._supports:
            raise AssertionError('Can not save this object type')

        values = {}
        for key in [key for key in self.keys() if key not in self._save_ignore]:
            if not getattr(self, key) and getattr(self, key) != False:
                continue

            if isinstance(getattr(self, key, None), list):
                value = list()
                for item in getattr(self, key):
                    if isinstance(item, dict):
                        value.append(item)
                    elif hasattr(item, '_save_as'):
                        value.append(item._save_as())
                    elif hasattr(item, '_ref') and getattr(item, '_ref'):
                        value.append(getattr(item, '_ref'))
                    else:
                        LOGGER.warning('Cant assign %r', item)
                values[key] = value
            elif getattr(self, key, None):
                values[key] = getattr(self, key)
        if not self._ref:
            response = self._session.post(self._path, values)
        else:
            values['_ref'] = self._ref
            response = self._session.put(self._path, values)
        LOGGER.debug('Response: %r, %r', response.status_code, response.content)
        if 200 <= response.status_code <= 201:
            self.fetch()
            return True
        else:
            try:
                error = response.json()
                raise exceptions.ProtocolError(error['text'])
            except ValueError:
                raise exceptions.ProtocolError(response.content)
309454
def save(self):
        

        # TODO: Add option force_insert

        if not self.is_loaded and self.id is None or self.id == '':
            data = self.resource.post(data=self.data, collection=self.collection)
            self.id = data['_id']
            self.key = data['_key']
            self.revision = data['_rev']
            self.is_loaded = True
        else:
            data = self.resource(self.id).patch(data=self.data)
            self.revision = data['_rev']
1007121
def save(self, obj):
        
        if obj not in self.session:
            self.session.add(obj)
        else:
            obj = self.session.merge(obj)
        self.session.flush()
        self.session.refresh(obj)
        return obj