This is responsible for building the surrogate id from the model
975528
def get_surrogate_id(self):
        
        surrogate_id = "%s,%s,%s,%s,%s" % (self.year,
                                           self.quarter,
                                           self.curriculum_abbr.lower(),
                                           self.course_number,
                                           self.section_id.lower())

        return surrogate_id
313714
def build_associate(model, options = {})
      model_name                = model.to_s.underscore
      model_klass               = (options[:class_name] || model).to_s.classify.constantize
      dependent_associate_names = options[:depends_on].map(&:to_s)
      attribute_names           = extract_attribute_names(model_klass, options)

      ensure_name_uniqueness(associates.map(&:name), model_name)
      ensure_attribute_uniqueness(associates.map(&:attribute_names), attribute_names) if options[:delegate]
      ensure_dependent_names_existence(associates.map(&:name), dependent_associate_names)

      Item.new(model_name, model_klass, attribute_names, dependent_associate_names, options)
    end
1152211
function( attributes, options ) {
			var model = this;

			// 'build' is a possible entrypoint; it's possible no model hierarchy has been determined yet.
			this.initializeModelHierarchy();

			// Determine what type of (sub)model should be built if applicable.
			// Lookup the proper subModelType in 'this._subModels'.
			if ( this._subModels && this.prototype.subModelTypeAttribute in attributes ) {
				var subModelTypeAttribute = attributes[ this.prototype.subModelTypeAttribute ];
				var subModelType = this._subModels[ subModelTypeAttribute ];
				if ( subModelType ) {
					model = subModelType;
				}
			}
			
			return new model( attributes, options );
		}
1058960
function (model) {
            this._super(arguments);
            var ctiKey = this.__ctiKey = model.__ctiKey;
            this.__ctiTables = model.__ctiTables.slice();
            this.__ctiModels = model.__ctiModels.slice();
            this.__ctiModels.push(this);
            this.__ctiTables.push(this.tableName);
            this.__ctiColumns = comb.merge({}, model.__ctiColumns);
            this.__ctiColumns[this.tableName] = this.columns;
            this.__ctiBaseModel = model.__ctiBaseModel;
            //copy over our schema
            var newSchema = comb.merge({}, this.__schema);
            var schemas = model.__ctiModels.map(
                function (m) {
                    return m.schema;
                }).reverse();
            schemas.forEach(function (s) {
                for (var i in s) {
                    newSchema[i] = s[i];
                }
            }, this);
            this._setSchema(newSchema);
            this._setDataset(model.dataset.join(this.tableName, this.primaryKey));
            this._setPrimaryKey(this.__ctiBaseModel.primaryKey);
            this.pre("save", function (next) {
                if (ctiKey) {
                    this[ctiKey] = this.tableName.toString();
                }
                next();
            });
        }
1328198
def make_model(self):
        """"""
        for stmt in self.statements:
            if isinstance(stmt, Modification):
                card = assemble_modification(stmt)
            elif isinstance(stmt, SelfModification):
                card = assemble_selfmodification(stmt)
            elif isinstance(stmt, Complex):
                card = assemble_complex(stmt)
            elif isinstance(stmt, Translocation):
                card = assemble_translocation(stmt)
            elif isinstance(stmt, RegulateActivity):
                card = assemble_regulate_activity(stmt)
            elif isinstance(stmt, RegulateAmount):
                card = assemble_regulate_amount(stmt)
            else:
                continue
            if card is not None:
                card.card['meta'] = {'id': stmt.uuid, 'belief': stmt.belief}
                if self.pmc_override is not None:
                    card.card['pmc_id'] = self.pmc_override
                else:
                    card.card['pmc_id'] = get_pmc_id(stmt)
                self.cards.append(card)
745858
function(model, options) {
      this._byId[model.cid] = model;
      if (model.id != null) this._byId[model.id] = model;
      if (!model.collection) model.collection = this;
      model.on('all', this._onModelEvent, this);
    }
65415
def make_model(self):
        """"""
        # Assemble in two stages.
        # First, create the nodes of the graph
        for stmt in self.statements:
            # Skip SelfModification (self loops) -- has one node
            if isinstance(stmt, SelfModification) or \
               isinstance(stmt, Translocation) or \
               isinstance(stmt, ActiveForm):
                continue
            # Special handling for Associations -- more than 1 node and members
            # are Events
            elif isinstance(stmt, Association):
                for m in stmt.members:
                    self._add_node(m.concept)
            # Special handling for Complexes -- more than 1 node
            elif isinstance(stmt, Complex):
                for m in stmt.members:
                    self._add_node(m)
            # All else should have exactly 2 nodes
            elif all([ag is not None for ag in stmt.agent_list()]):
                if not len(stmt.agent_list()) == 2:
                    logger.warning(
                        '%s has less/more than the expected 2 agents.' % stmt)
                    continue
                for ag in stmt.agent_list():
                    self._add_node(ag)
        # Second, create the edges of the graph
        for stmt in self.statements:
            # Skip SelfModification (self loops) -- has one node
            if isinstance(stmt, SelfModification) or \
               isinstance(stmt, Translocation) or \
               isinstance(stmt, ActiveForm):
                continue
            elif isinstance(stmt, Association):
                self._add_complex(stmt.members, is_association=True)
            elif isinstance(stmt, Complex):
                self._add_complex(stmt.members)
            elif all([ag is not None for ag in stmt.agent_list()]):
                self._add_stmt_edge(stmt)
517090
private void createCompleteKey(Key parent, long id) {
    String kind = entityMetadata.getKind();
    if (parent == null) {
      key = entityManager.newNativeKeyFactory().setKind(kind).newKey(id);
    } else {
      key = Key.newBuilder(parent, kind, id).build();
    }
  }
246336
function buildModelUrl (protocol, host, apiRoot, modelName, id) {
  var result

  try {
    result = url.format({
      protocol: protocol,
      host: host,
      pathname: url.resolve('/', [apiRoot, modelName, id].join('/'))
    })
  } catch (e) {
    return ''
  }

  return result
}
939659
function ()
		{
			for (c in this.c)
			{
				if (this.c[c].build && this.c[c].build.extend && this.c[c].build.extend.indexOf('wnActiveRecord')!=-1)
				{
					this.prepareModel(c);
				}
			}
		}
939936
protected function setupNamedModel()
    {
        if (!$this->getModel() || !$this->getName()) {
            return;
        }

        $model = $this->formHelper->convertModelToArray($this->getModel());

        if (!array_get($model, $this->getName())) {
            $this->model = [
                $this->getName() => $model
            ];
        }
    }
49326
def replace_surrogates(self, m):
        """"""

        high, low = ord(m.group(1)), ord(m.group(2))
        return chr((high - 0xD800) * 0x400 + low - 0xDC00 + 0x10000)
1207564
function buildWhereModel (name, value, alias) {
    // skip updefined values
    if (value === undefined) {
        return
    }
    // get id columns for model
    var idColumn = this.model.columnName('id')
    var originalIdColumn = this.model.columnName('originalId')
    // model column belongs to
    var model
    // column spec
    var spec
    // isDeleted where clause
    if (name === 'isDeleted') {
        // if value is null do nothing
        if (value === null) {
            return
        }
        // change column name to real column name (d)
        name = 'd'
    }
    // join column where clause
    if (name.match(/\./)) {
        var [prefix, column] = name.split('.')
        // prefix is for join
        if (this.joinRelations[prefix]) {
            // get join
            var join = this.joinRelations[prefix]
            // get relation
            var relation = this.model.relation(prefix)
            // set model for where clause
            model = relation.model
            // get column name from relation model
            name = model.columnName(column, true)
            // get spec
            spec = model.columns[name]
            // get alias
            alias = join.relationAlias
        }
        // error
        else {
            throw new Error('invalid column name in where '+name)
        }
    }
    // where clause for column on primary model table
    else {
        // model is base model
        model = this.model
        // validate column name - throw error
        name = this.model.columnName(name, true)
        // get column spec
        spec = this.model.columns[name]
        // if value is set for only the first column then need to add join to
        // select the record that matches the value
        if (spec.firstOnly) {
            // get new alias for primary table
            alias = this.newAlias(this.table)
            // add join
            this.join.push( this.joinSql(this.table, alias, originalIdColumn, this.alias, originalIdColumn) )
        }
    }
    // if optional alias is not set then get table alias for model name
    if (!alias) {
        alias = this.getAlias(model.name)
    }
    // flag set to true if this is negated statement
    var isNot = false
    // every where statement will begin with the alias and column name
    var whereSql = `${alias}.${this.quoteName(name)}`
    // if value is a string then do a simple column = :value
    if (typeof value === 'string' || typeof value === 'number') {
        // get param name for value placeholder
        var paramName = this.newParam(name)
        // set value for param placeholder
        this.params[paramName] = value
        // create sql
        whereSql += spec.type === 'id' && this.model.binaryIds
            ? ` = UNHEX(:${paramName})`
            : ` = :${paramName}`
    }
    // if value is boolean then do column = 1|0
    else if (spec.type === 'boolean' && typeof value === 'boolean') {
        // get param name for value placeholder
        var paramName = this.newParam(name)
        // create sql
        whereSql += ` = ${value ? 1 : 0}`
    }
    // if value is array then do IN () query
    else if (Array.isArray(value)) {
        var placeholders = _.map(value, v => {
            // get param name for each placeholder
            var paramName = this.newParam(name)
            // set value for param placeholder
            this.params[paramName] = v
            // create placeholder
            return spec.type === 'id' && this.model.binaryIds
                ? `UNHEX(:${paramName})`
                : `:${paramName}`
        })
        // create sql
        whereSql += ` IN(${placeholders.join(', ')})`
    }
    // if value is null then do IF NULL
    else if (value === null) {
        // create sql
        whereSql += ' IS NULL'
    }
    // if value is object then it should be a match type and value
    else if (typeof value === 'object') {
        // get keys of object
        var keys = _.keys(value)
        // there should be only one key
        assert.equal(keys.length, 1, 'statement must have one comparison operator in where '+name)
        // get operator
        var operator = keys[0]
        // get value
        var operatorValue = value[operator]
        var operatorValueType = typeof operatorValue
        // validate operator value
        if (operatorValueType === 'object' && operator !== 'in' && operator !== 'between' && operator !== 'not') {
            // if value is array change the type from object to array
            if (Array.isArray(operatorValue)) {
                operatorValueType = 'array'
            }
            // throw error
            throw new Error(`${model.name} query error: invalid value type '${operatorValueType}' for operator '${operator}'`)
        }
        // if operator is not then need to get next level deeper
        if (operator === 'not') {
            // if value is null than do IF NULL
            if (operatorValue === null) {
                // create sql
                whereSql += ' IS NOT NULL'
                // add sql to list of where clauses
                this.where.push(whereSql)
                // TODO: refactor this
                return
            }
            else {
                // get keys of not object
                keys = _.keys(operatorValue)
                // there should be only one key
                assert.equal(keys.length, 1, 'statement must have one comparison operator in where '+name)
                // get operator
                operator = keys[0]
                // get value
                operatorValue = operatorValue[operator]
                // set flag to negate statement
                isNot = true
            }
        }
        // LIKE :value
        if (operator === 'like') {
            // get param name for value placeholder
            var paramName = this.newParam(name)
            // set value for param placeholder
            this.params[paramName] = operatorValue
            // create sql
            whereSql += ` LIKE :${paramName}`
        }
        // > : value
        else if (operator === 'gt') {
            // get param name for value placeholder
            var paramName = this.newParam(name)
            // set value for param placeholder
            this.params[paramName] = operatorValue
            // create sql
            whereSql += ` > :${paramName}`
        }
        // >= : value
        else if (operator === 'gte') {
            // get param name for value placeholder
            var paramName = this.newParam(name)
            // set value for param placeholder
            this.params[paramName] = operatorValue
            // create sql
            whereSql += ` >= :${paramName}`
        }
        // < : value
        else if (operator === 'lt') {
            // get param name for value placeholder
            var paramName = this.newParam(name)
            // set value for param placeholder
            this.params[paramName] = operatorValue
            // create sql
            whereSql += ` < :${paramName}`
        }
        // <= : value
        else if (operator === 'lte') {
            // get param name for value placeholder
            var paramName = this.newParam(name)
            // set value for param placeholder
            this.params[paramName] = operatorValue
            // create sql
            whereSql += ` <= :${paramName}`
        }
        else if (operator === 'between') {
            assert.ok(Array.isArray(operatorValue), 'between value must be array in where '+name)
            assert.equal(operatorValue.length, 2, 'between array must have 2 elements in where '+name)
            // get param name for value placeholder
            var paramName1 = this.newParam(name)
            // set value for param placeholder
            this.params[paramName1] = operatorValue[0]
            // get param name for value placeholder
            var paramName2 = this.newParam(name)
            // set value for param placeholder
            this.params[paramName2] = operatorValue[1]
            // create sql
            whereSql += ` BETWEEN :${paramName1} AND :${paramName2}`
        }
        else if (operator === 'in') {
            assert.ok(Array.isArray(operatorValue), 'in value must be array in where '+name)
            // get placeholder for each in value
            var placeholders = _.map(operatorValue, v => {
                // get param name for each placeholder
                var paramName = this.newParam(name)
                // set value for param placeholder
                this.params[paramName] = v
                // create placeholder
                return spec.type === 'id' && this.model.binaryIds
                    ? `UNHEX(:${paramName})`
                    : `:${paramName}`
            })
            // create sql
            whereSql += ` IN(${placeholders.join(', ')})`
        }
        // = : value
        else if (operator === 'eq') {
            // get param name for value placeholder
            var paramName = this.newParam(name)
            // set value for param placeholder
            this.params[paramName] = operatorValue
            // create sql
            whereSql += spec.type === 'id' && this.model.binaryIds
                ? ` = UNHEX(:${paramName})`
                : ` = :${paramName}`
        }
        // operator type not supported
        else {
            throw new Error('invalid operator '+operator+' in where '+name)
        }
    }
    // query type not supported
    else {
        throw new Error('invalid value type '+typeof value+' in where '+name)
    }

    // if this is NOT statement then wrap in negation
    if (isNot) {
        whereSql = '!('+whereSql+')'
    }

    // add sql to list of where clauses
    this.where.push(whereSql)
}
220799
function( model, options ) {
			if ( this.related ) {
				return;
			}
			options = this.sanitizeOptions( options );
			
			var item = this.keyContents;
			if ( item || item === 0 ) { // since 0 can be a valid `id` as well
				var id = Backbone.Relational.store.resolveIdForItem( this.relatedModel, item );
				if ( !_.isNull( id ) && model.id === id ) {
					this.addRelated( model, 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;
    }
230322
public <S extends Model> int updateById(S model, Serializable id) {
        this.where(primaryKeyColumn, id);
        String       sql             = this.buildUpdateSQL(model, null);
        List<Object> columnValueList = AnimaUtils.toColumnValues(model, false);
        columnValueList.add(id);
        return this.execute(sql, columnValueList);
    }
923568
private void initSurrogateMap(Map<String, List<String>> targetCapabilities,
            SurrogateCapabilitiesHeader surrogateCapabilitiesHeader) {

        for (SurrogateCapabilities sc : surrogateCapabilitiesHeader.getSurrogates()) {
            targetCapabilities.put(sc.getDeviceToken(), new ArrayList<String>());
        }
    }