## BaseModel.prototype.saveAll

Save Model & its relations
Note: Collection relations are not saved

@param {Object} options Options
@returns {Promise} promise
176027
function(options) {
    options = options || {};
    var fns = [
      _.bind(this.save, this, null, options)
    ];
    _.each(this.relationDefinitions, function(relationAttributes, relationKey) {
      var relation = this.get(relationKey);
      if (relation && _.isFunction(relation.save)) {
        fns.push(_.bind(relation.save, relation, null, _.clone(options)));
      }
    }, this);
    return sequence(fns);
  }
669595
function makerelation (model, relation) {
	let options = {
		as: relation.As,
		foreignKey: relation.key
	};
	let target = exp.databases[inflector.pluralize(relation.Children)];
	if (relation.Rel !== 'manyToMany') {
		exp.databases[model][relation.Rel](target, options);
	} else {
		exp.databases[model].prototype.many2many = exp.databases[model].prototype.many2many || {};
		exp.databases[model].prototype.many2many[relation.Parent] = function (id, id2) {
			if (id && id2) {
				return exp.databases[relation.Children].findcre({
					[`${model}ID`]: id,
					[`${relation.Parent}ID`]: id2
				});
			}
			return exp.databases[relation.Children].find({
				where: {
					[`${model}ID`]: id
				}
			}).then(records => {
				let all = [];
				for (const record of records) {
					all.push(exp.databases[relation.Parent].findById(record[`${relation.Parent}ID`]));
				}
				return Promise.all(all);
			});
		};
	}
}
521849
function(model, options) {
    options = options ? extend({}, options) : {};
    if (!(model = this._prepareModel(model, options))){
      return false;
    }
    if (!options.wait){
      this.add(model, options);
    }
    var collection = this;
    options.cb = options.callback;
    options.callback = function cb(err, model, response){
      if (err){
        return callback(err, model, response, options);
      }
      if (options.wait){
        collection.add(model, options);
      }
      callback(null, model, response, options);
    };

    model.save(null, options);
    return model;
  }
262989
def save(options = {})
      _run_save_callbacks do 
        raise GitModel::NullId unless self.id

        if new_record?
          raise GitModel::RecordExists if self.class.exists?(self.id)
        else
          raise GitModel::RecordDoesntExist unless self.class.exists?(self.id)
        end

        GitModel.logger.debug "Saving #{self.class.name} with id: #{id}"

        dir = File.join(self.class.db_subdir, self.id)

        transaction = options.delete(:transaction) || GitModel::Transaction.new(options) 
        result = transaction.execute do |t|
          # Write the attributes to the attributes file
          t.index.add(File.join(dir, 'attributes.json'), Yajl::Encoder.encode(attributes, nil, :pretty => true))

          # Write the blob files
          blobs.each do |name, data|
            t.index.add(File.join(dir, name), data)
          end
        end

        if result
          @path = dir
          @branch = transaction.branch
          @new_record = false
        end

        result
      end
    end
1055447
function save(model) {
      var _this = this;
      var record = this.records.get(model);
      model = record || this._ensureModel(model);
      return Promise.resolve(model.save()).then(function () {
        if (!record) {
          _this.insert(model);
        }
        return model;
      });
    }
527101
def save_many(self, models, joinings=None):
        
        if joinings is None:
            joinings = {}

        for key, model in enumerate(models):
            self.save(model, joinings.get(key), False)

        self.touch_if_touching()

        return models
809371
public function save(...$args) : Collection
    {
        $collection = new Collection();

        foreach ($this->added as $current) {
            $return = $current->insert(...$args);
            $collection->add(new ModelSaved($current, $current->getChangedProperties(), $return));
        }

        foreach ($this->removed as $current) {
            $return = $current->delete(...$args);
            $collection->add(new ModelSaved($current, $current->getChangedProperties(), $return));
        }

        foreach ($this->elements as $current) {
            if (in_array($current, $this->added, true)) {
                continue;
            }

            $return = null;
            if (sizeof($current->getChangedProperties()) > 0) {
                $return = $current->update(...$args);
            }
            $collection->add(new ModelSaved($current, $current->getChangedProperties(), $return));
        }

        $this->clearHistory();

        return $collection;
    }
747591
public function save()
    {
        $model = $this->unwrap();
        $modelRelations = Cache::all($model);

        foreach ($modelRelations as $key => $mr) {
            $relation = Rel::make($mr['relation']);

            if ($relation->canSaveBefore()) {
                $relation->saveBefore($mr['child']);
            }
        }
        $model->save();

        foreach ($modelRelations as $key => $model) {
            $relation = Rel::make($mr['relation']);

            if ($relation->canSaveAfter()) {
                $relation->saveAfter($mr['child']);
            }
        }
    }
172541
function parseCollection (type, data, relations, options) {
  var result = []

  _.each(data, function (value) {
    result.push(parseResource(type, value, relations, options))
  })

  return result
}
794652
function initRelations (args) {
    // create map of relations
    this.relations = {}
    // get relations from args
    var relations = requireValidOptionalObject(args.relations)
    // validate and add relations
    _.each(relations, (relation, relatedModelName) => {
        this.relations[relatedModelName] = relation
    })
}
819662
function save(options) {
    const self = this
    options = options || {}

    if (self.options.polymorph) return this.callParent(options)

    return Promise.all(
      this.map(function(record) {
        // validate all records at once.
        return record.validate()
      })
    )
      .then(function() {
        // if validation succeeded, start the transaction
        return self.store.startTransaction(options, function() {
          return self
            ._runLazyOperation(options)
            .then(function() {
              // inside the transaction create all new records and afterwards save all the others
              return self._create(options)
            })
            .then(function() {
              // will save all existing records with changes...
              return self.callParent(options, save)
            })
        })
      })
      .then(function() {
        return self
      })
  }
16083
function(model_s, create, options){
      var toAdd = model_s instanceof Array ? model_s : [model_s],
          self = this;

      ko.utils.arrayForEach(toAdd, function(attributes){
        var model;
        if(attributes instanceof Model){
          model = attributes;
          model.collection = self;
        }else{
          model = new self.model(attributes, {collection: self});
        }
        self.models.push(model);
        if(create) model.save(options);
      });
    }
853173
function saveAsync(doc) {
  return new Promise(function (resolve, reject) {
    doc.save(function (err, doc) {
      /* istanbul ignore if: This should handle errors just fine */
      if (err) { return reject(err); }
      resolve(doc);
    });
  });
}
140154
function(model, cascade, options)
  {
    var db = this;

    // If we have it in the models, remove it!
    this.removeFromModels( model );

    // If we're offline and we have a pending save - cancel the pending save.
    if ( model.$status === Model.Status.SavePending )
    {
      Rekord.debug( Rekord.Debugs.REMOVE_CANCEL_SAVE, db, model );
    }

    model.$status = Model.Status.RemovePending;

    model.$addOperation( RemoveLocal, cascade, options );
  }
87461
function(options){
      var name = options.name
        , model = options.model
        , implementation = options.implementation
        , cid = options.cid;

      // save the new things by internal cid
      this._names[cid] = name;
      this._models[cid] = model;
      this._implementations[cid] = implementation;

      this._updateLength();

      return this;
    }
97420
public function save(array $options = [])
    {
        try {
            // Save model to database
            $result = parent::save($options);

            // If save has been aborted from an event/observer
            // or simply returned an empty response, we'll treat
            // it as a failed save and throw an exception.
            if (! $result) {
                throw new SaveFailedException(sprintf('Could not save model [%s]. Reason: Save returned false.', get_class($this)));
            }
        } catch (Exception $e) {
            // Catch exceptions and re-throw
            // as our Nodes "save failed" exceptions
            throw (new SaveFailedException(sprintf('Could not save model [%s]. Reason: %s', get_class($this), $e->getMessage())))->setPreviousException($e);
        } catch (Throwable $e) {
            // Add support for PHP 7 throwable interface.
            // Re-throw as our Nodes "save failed" exceptions.
            throw (new SaveFailedException(sprintf('Could not save model [%s]. Reason: %s', get_class($this), $e->getMessage())))->setPreviousException($e);
        }

        return $result;
    }
490235
function (model, options) {
        this._index(model);
        if (!model.collection) model.collection = this;
        if (model.on) model.on('all', this._onModelEvent, this);
    }