Add one or more models to collection and optionally create them on the server setting the 'create' parameter to 'true' It will also add a reference to the collection on each model
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);
      });
    }
646381
function(model, options) {
      var coll = this;
      options || (options = {});
      model = this._prepareModel(model, options);
      if (!model) return false;
      var success = options.success;
      options.success = function(nextModel, resp, xhr) {
        coll.add(nextModel, options);
        if (success) success(nextModel, resp, xhr);
      };
      model.save(null, options);
      return model;
    }
410513
def _attach_to_model(self, model):
        
        super(RelatedFieldMixin, self)._attach_to_model(model)

        if model.abstract:
            # do not manage the relation if it's an abstract model
            return

        # now, check related_name and save the relation in the database

        # get related parameters to identify the relation
        self.related_name = self._get_related_name()
        self.related_to = self._get_related_model_name()

        # create entry for the model in the _relations list of the database
        if not hasattr(self.database, '_relations'):
            self.database._relations = {}
        self.database._relations.setdefault(self.related_to, [])

        # check unicity of related name for related model
        self._assert_relation_does_not_exists()

        # the relation didn't exists, we can save it
        relation = (self._model._name, self.name, self.related_name)
        self.database._relations[self.related_to].append(relation)
370569
function (collection, data, action, options) {
                if (!(data instanceof Array)) {
                    throw "data has to be an array";
                }
                var context,
                    entity,
                    newData = [];
                for (var i = 0; i < data.length; i++) {
                    var value = data[i];
                    if (!(value instanceof Model)) {
                        // this is needed to determine the right context for collection models that are just links inside the collection
                        context = this.$dataSource._getContext(collection.$modelFactory, collection, value);
                        entity = context.createEntity(collection.$modelFactory, this._getIdForValue(value, collection.$modelFactory));
                        entity.set(this._parseModel(entity, value, action, options));
                        newData.push(entity);
                    }
                }

                return newData;
            }
995119
def add(self, **args):
        
        kwargs = self.getKwargs(args)
        if kwargs:
            self.model.add(**kwargs)
310035
public <T extends Model>  void addModels(List<T> models){
        for (T model : models) {
            add(model);
        }
    }
930408
function(models, options) {
            options = _.defaults(options || {}, {
                totalCount: false
            });

            // Manage {list:[], n:0} for infinite list
            if (_.size(models) == 2
            && models.list != null && models.n != null) {
                this._totalCount = models.n;
                return this.reset(models.list, options);
            }

            // Remove reference
            for (var i = 0, length = this.models.length; i < length; i++) {
                this._removeReference(this.models[i], options);
            }
            options.previousModels = this.models;
            this.options.startIndex = 0;
            this.models = [];
            this._byId = {};
            if (options.totalCount) this._totalCount = null;
            this.add(models, _.extend({silent: true}, options || {}));
            options = _.defaults(options || {}, {
                silent: false
            });
            if (!options.silent) this.trigger('reset', this, options);
            return this;
        }
788192
def new_collection(query, resources = nil, &block)
      if loaded?
        resources ||= filter(query)
      end

      # TOOD: figure out a way to pass not-yet-saved Resources to this newly
      # created Collection.  If the new resource matches the conditions, then
      # it should be added to the collection (keep in mind limit/offset too)

      self.class.new(query, resources, &block)
    end
286152
async def create(self, model_, **data):
        
        inst = model_(**data)
        query = model_.insert(**dict(inst.__data__))

        pk = await self.execute(query)
        if inst._pk is None:
            inst._pk = pk
        return inst
1074687
def add(self, model):
        """"""
        def foo(m, p, i):
            if m[i][0].name == model.name:
                raise ValueError("Model already exists")
            return
        # checks if already existing
        self.foreach(foo)
        
        self.append((model,))
        return
226330
protected function addCollection()
    {
        if (!$this->isError()) {
            $id = $this->collection->add($this->getSubmitted());
            if (empty($id)) {
                $this->errorAndExit($this->text('Unexpected result'));
            }
            $this->line($id);
        }
    }
172045
def add_collection(collection,
                   cache_size=1000,
                   cache_cls=LRUCache,
                   **cache_args):
    """"""
    assert collection not in _db
    cache = cache_cls(maxsize=cache_size,
                      missing=lambda id: load_object(collection, id),
                      **cache_args)
    _db[collection] = aadict(cache=cache, indexes={})
658647
def perform_create(self, serializer):
        """"""
        process = serializer.validated_data.get('process')
        if not process.is_active:
            raise exceptions.ParseError(
                'Process retired (id: {}, slug: {}/{}).'.format(process.id, process.slug, process.version)
            )

        with transaction.atomic():
            instance = serializer.save()

            assign_contributor_permissions(instance)

            # Entity is added to the collection only when it is
            # created - when it only contains 1 Data object.
            entities = Entity.objects.annotate(num_data=Count('data')).filter(data=instance, num_data=1)

            # Assign data object to all specified collections.
            collection_pks = self.request.data.get('collections', [])
            for collection in Collection.objects.filter(pk__in=collection_pks):
                collection.data.add(instance)
                copy_permissions(collection, instance)

                # Add entities to which data belongs to the collection.
                for entity in entities:
                    entity.collections.add(collection)
                    copy_permissions(collection, entity)
2194
function(model, options) {
      options || (options = {});
      model = this._prepareModel(model, options);
      if (!model) return false;
      var already = this.getByCid(model) || this.get(model);
      if (already) throw new Error(["Can't add the same model to a set twice", already.id]);
      this._byId[model.id] = model;
      this._byCid[model.cid] = model;
      var index = options.at != null ? options.at :
                  this.comparator ? this.sortedIndex(model, this.comparator) :
                  this.length;
      this.models.splice(index, 0, model);
      model.bind('all', this._onModelEvent);
      this.length++;
      if (!options.silent) model.trigger('add', model, this, options);
      return model;
    }
694335
def create(cls, **kwargs):
        
        extra_columns = set(kwargs.keys()) - set(cls._columns.keys())
        if extra_columns:
            raise ValidationError("Incorrect columns passed: {0}".format(extra_columns))
        return cls.objects.create(**kwargs)
1278095
function(models, options) {
      return this.set(models, _.extend({merge: false}, options, addOptions));
    }
1307325
def _post_create(self, auto_refresh=False):

		'''
		
		'''

		# set PCDM triple as Collection
		self.add_triple(self.rdf.prefixes.rdf.type, self.rdf.prefixes.pcdm.File)
		self.update(auto_refresh=auto_refresh)