Internal implementation of adding a single model to the set, updating hash indexes for `id` and `cid` lookups. Returns the model, or 'false' if validation on a new model fails.
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;
    }
1250138
def get_concrete_model(model):
    
    if not(inspect.isclass(model) and issubclass(model, models.Model)):
        model = get_model_by_name(model)

    return model
1252650
def add(self, models):
        
        if models is None:
            return

        models = self._check_model_types(models)
        self._selected.update(models)
        self._selected = reduce_to_parent_states(self._selected)
1003250
function(o, callback) {
    
    var self = this;

    // Note: Validation has already been performed by ModelObject
    
    // Convert `id` to `_id`
    convertMongoID(o);
    
    // Get _id, and prepare update data
    var _id = o._id;
    delete o._id;
    
    if (typeof _id == 'undefined') {
      callback.call(this, new Error("Unable to update model object without ID"));
      return;
    }
    
    // Validate, throw error on failure
    var err = this.validateProperties(o, {noRequired: true});
    
    if (err) callback.call(self, err);
    
    else {
      
      this.driver.updateById({
        _id: _id,
        collection: this.context,
        values: o
      }, function(err, docs) {
        callback.call(self, err);
      });
      
    }
    
  }
966754
def add_model(self, metric_value, model_id):
        
        if self.verbose:
            logger.info("Saving model.")

        # Update best_model text file
        ret = {"model_id": model_id, "metric_value": metric_value}
        self.history.append(ret)
        if model_id == self.get_best_model_id():
            file = open(os.path.join(self.path, "best_model.txt"), "w")
            file.write("best model: " + str(model_id))
            file.close()
        return ret
210396
def register_model(self, *index_fields, **kw):
        
        # construct subclass of AbstractWhoosheer for a model
        class ModelWhoosheer(AbstractWhoosheerMeta):
            @classmethod
            def _assign_primary(cls, primary, primary_is_numeric, attrs, model):
                attrs[primary] = getattr(model, primary)
                if not primary_is_numeric:
                    if sys.version < '3':
                        attrs[primary] = unicode(attrs[primary])
                    else:
                        attrs[primary] = str(attrs[primary])


        mwh = ModelWhoosheer

        def inner(model):
            mwh.index_subdir = model.__tablename__
            mwh.models = [model]

            schema_attrs = {}
            for field in model.__table__.columns:
                if field.primary_key:
                    primary = field.name
                    primary_is_numeric = True
                    if isinstance(field.type, SQLInteger):
                        schema_attrs[field.name] = whoosh.fields.NUMERIC(stored=True, unique=True)
                    else:
                        primary_is_numeric = False
                        schema_attrs[field.name] = whoosh.fields.ID(stored=True, unique=True)
                elif field.name in index_fields:
                    schema_attrs[field.name] = whoosh.fields.TEXT(**kw)
            mwh.schema = whoosh.fields.Schema(**schema_attrs)
            # we can't check with isinstance, because ModelWhoosheer is private
            # so use this attribute to find out
            mwh._is_model_whoosheer = True

            @classmethod
            def update_model(cls, writer, model):
                attrs = {}
                cls._assign_primary(primary, primary_is_numeric, attrs, model)
                for f in index_fields:
                    attrs[f] = getattr(model, f)
                    if not isinstance(attrs[f], int):
                        if sys.version < '3':
                            attrs[f] = unicode(attrs[f])
                        else:
                            attrs[f] = str(attrs[f])
                writer.update_document(**attrs)

            @classmethod
            def insert_model(cls, writer, model):
                attrs = {}
                cls._assign_primary(primary, primary_is_numeric, attrs, model)
                for f in index_fields:
                    attrs[f] = getattr(model, f)
                    if not isinstance(attrs[f], int):
                        if sys.version < '3':
                            attrs[f] = unicode(attrs[f])
                        else:
                            attrs[f] = str(attrs[f])
                writer.add_document(**attrs)

            @classmethod
            def delete_model(cls, writer, model):
                writer.delete_by_term(primary, getattr(model, primary))

            setattr(mwh, '{0}_{1}'.format(UPDATE_KWD, model.__name__.lower()), update_model)
            setattr(mwh, '{0}_{1}'.format(INSERT_KWD, model.__name__.lower()), insert_model)
            setattr(mwh, '{0}_{1}'.format(DELETE_KWD, model.__name__.lower()), delete_model)
            model._whoosheer_ = mwh
            model.whoosh_search = mwh.search
            self.register_whoosheer(mwh)
            return model

        return inner
1130002
function (id, cb) {
    var self = this;
    var idObj = {};
    idObj[this.model.prototype.idAttribute] = id;
    var model = new this.model(idObj, {collection: this});
    model.fetch({
      callback: function (err) {
        if(err){
          delete model.collection;
          if (cb){
            cb(Error('not found'));
          }
          return;
        }
        self.add(model);
        if (cb){
          return cb(null, model);
        }
      }
    });
  }
1219892
def addModel(self, moduleName, modelName, model):
        
        modelIdentifier = "{}.{}".format(moduleName, modelName)
        if modelIdentifier not in self._models:
            self._models[modelIdentifier] = model
        else:
            message = "Application - addModel() - " \
                      "A model with the identifier {} already exists." \
                      .format(modelIdentifier)
            raise Exception(message)
1096415
def recursive_model_update(model, props):
    
    updates = {}
    valid_properties = model.properties_with_values()
    for k, v in props.items():
        if isinstance(v, Model):
            nested_model = getattr(model, k)
            if type(v) is type(nested_model):
                nested_props = v.properties_with_values(include_defaults=False)
                recursive_model_update(nested_model, nested_props)
            else:
                setattr(model, k, v)
        elif k in valid_properties and v != valid_properties[k]:
            updates[k] = v
    model.update(**updates)
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
616733
def update_model(self):
        
        '''
             
        '''
        
        import requests
        url = self.endpoint_public + '/calculate'
        params = {
            'group': self.group_name
        }
        response = requests.get(url, params=params)
        response_details = response.json()
        
        return response_details['success']
200827
def has_model(self, model):
        
        # TODO:
        # - accept DigitalObject for model?
        # - convert model pid to info:fedora/ form if not passed in that way?
        try:
            rels = self.rels_ext.content
        except RequestFailed:
            # if rels-ext can't be retrieved, confirm this object does not have a RELS-EXT
            # (in which case, it does not subscribe to the specified content model)
            if "RELS-EXT" not in self.ds_list.keys():
                return False
            else:
                raise

        st = (self.uriref, modelns.hasModel, URIRef(model))
        return st in rels
475681
def _add_single_session_to_to_ordered_dict(self, d, dataset_index, recommended_only):
        
        for model_index, model in enumerate(self.models):
            # determine if model should be presented, or if a null-model should
            # be presented (if no model is recommended.)
            show_null = False
            if recommended_only:
                if self.recommendation_enabled:
                    if self.recommended_model is None:
                        if model_index == 0:
                            show_null = True
                        else:
                            continue
                    elif self.recommended_model == model:
                        pass
                    else:
                        continue
                else:
                    if model_index == 0:
                        show_null = True
                    else:
                        continue

            d["dataset_index"].append(dataset_index)
            d["doses_dropped"].append(self.doses_dropped)
            model._to_df(d, model_index, show_null)
148692
def append_lookup_key(model, lookup_key):
    ""
    pieces = lookup_key.split('__', 1)

    fields = append_translated(model, (pieces[0],))

    if len(pieces) > 1:
        # Check if we are doing a lookup to a related trans model
        fields_to_trans_models = get_fields_to_translatable_models(model)
        if pieces[0] in fields_to_trans_models:
            transmodel = fields_to_trans_models[pieces[0]]
            rest = append_lookup_key(transmodel, pieces[1])
            fields = set('__'.join(pr) for pr in itertools.product(fields, rest))
        else:
            fields = set('%s__%s' % (f, pieces[1]) for f in fields)
    return fields
995119
def add(self, **args):
        
        kwargs = self.getKwargs(args)
        if kwargs:
            self.model.add(**kwargs)
521427
def find_model_by_id(self, constructor, id_, *, columns=None):
    
    return self.find_model(
      constructor, get_id_constraints(constructor.primary_key_name, id_), columns=columns)
439161
def add_model(self, allow_alias=False, **kwargs):
        """"""
        if not allow_alias and MODEL.ALIAS in kwargs:
            err_str = "`{}` passed in kwargs, this shouldn't happen!".format(
                SOURCE.ALIAS)
            self._log.error(err_str)
            raise RuntimeError(err_str)

        # Set alias number to be +1 of current number of models
        if MODEL.ALIAS not in kwargs:
            kwargs[MODEL.ALIAS] = str(self.num_models() + 1)
        model_obj = self._init_cat_dict(Model, self._KEYS.MODELS, **kwargs)
        if model_obj is None:
            return None

        for item in self.get(self._KEYS.MODELS, ''):
            if model_obj.is_duplicate_of(item):
                return item[item._KEYS.ALIAS]

        self.setdefault(self._KEYS.MODELS, []).append(model_obj)
        return model_obj[model_obj._KEYS.ALIAS]