Generates a definition for a single model type
@param {*} model
16665
function mapType(model) {
    types[model.modelName] = {
        generated: false,
        name: model.modelName,
        meta: {
            category: 'TYPE',
            fields: {}
        }
    };

    _.forEach(model.definition.properties, (property, key) => {
        mapProperty(model, property, model.modelName, key);
    });

    _.forEach(sharedRelations(model), (rel) => {
        mapRelation(rel, model.modelName, rel.name);
    });
}
104971
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;
      var success = options.success;
      options.success = function(model, resp) {
        if (options.wait) collection.add(model, options);
        if (success) success(model, resp, options);
      };

      var savePromise = model.save(null, options);
      if (savePromise) {
        savePromise.catch(function(err) {});
      }
      return model;
    }
396072
function( model ) {
			if ( model instanceof Backbone.RelationalModel ) {
				model = model.constructor;
			}
			
			var rootModel = model;
			while ( rootModel._superModel ) {
				rootModel = rootModel._superModel;
			}
			
			var coll = _.detect( this._collections, function( c ) {
					return c.model === rootModel;
				});
			
			if ( !coll ) {
				coll = this._createCollection( rootModel );
			}
			
			return coll;
		}
411124
function buildSchema(models, typeMap) {
  let type;

  var _models$map$reduce = models.map(model => {
    type = typeMap[model.modelName];
    return {
      query: (0, _buildQuery2.default)(model, type),
      mutation: (0, _buildMutation2.default)(model, type)
    };
  }).reduce((fields, modelField) => {
    fields.query = (0, _assign2.default)({}, fields.query, modelField.query);
    fields.mutation = (0, _assign2.default)({}, fields.mutation, modelField.mutation);
    return fields;
  }, { query: {}, mutation: {} });

  const query = _models$map$reduce.query;
  const mutation = _models$map$reduce.mutation;


  return {
    query: query,
    mutation: mutation
  };
}
441287
function isModel(object) {
    if (!object || typeof object !== 'object') {
        return false;
    }
    else if ('isModel' in object) {
        diag.debug.assert(function () { return object.isModel === Model.prototype.isPrototypeOf(object); });
        return object.isModel;
    }
    else {
        return Model.prototype.isPrototypeOf(object);
    }
}
1197038
function modelItem(data, model) {
    var res = {};

    utils.defineProperties(res, {
        _isModelItem: { value: true },

        model: { value: model.value },

        update: { value: function(data, sync) {
            if (sync == null) sync = true;

            return update(res, model, data).then(function() {
                if (!sync) return;
                return res.save();
            });
        } },

        save: { value: function() {
            if (_.has(res, 'id')) {
                var props = serverProperties(res, model);
                return utils.socketPost(model.io, model.url + '/update/' + res.id, props.properties).then(function() {
                    return Promise.all(_.map(props.refresh, function(item) {
                        return item.refresh();
                    }));
                });
            }
            return create(res, model);
        } },

        refresh: { value: function() {
            if (!_.has(res, 'id')) return create(res, model);

            return utils.socketGet(model.io, model.url + '/' + res.id).then(function(data) {
                return update(res, model, data, { noRefresh: true });
            });
        } },

        delete: { value: function() {
            model._removeItem(res);
            return utils.socketDelete(model.io, model.url, { id: res.id });
        } },

        matches: { value: function(query) {
            return utils.socketGet(model.io, model.url, query).then(function(r) {
                for (var i = 0; i < r.length; i++) {
                    if (r[i].id === res.id) return true;
                }
                return false;
            });
        } },

        then: { value: function() {
            return res.ready.then.apply(res.ready, arguments);
        } },

        catch: { value: function() {
            return res.ready.catch.apply(res.ready, arguments);
        } }
    });

    res.ready = Promise.resolve();

    update(res, model, data || {});

    return res;
}
202758
function(model, options) {
      if (!(model instanceof Backbone.Model)) {
        var attrs = model;
        model = new this.model(attrs, {collection: this});
        if (model.validate && !model._performValidation(attrs, options)) model = false;
      } else if (!model.collection) {
        model.collection = this;
      }
      return model;
    }
9030
function(model)
  {
    var exists = this.has( model.$key() );
    var matches = this.filter( model );

    if ( exists && !matches )
    {
      this.remove( model );
    }
    if ( !exists && matches )
    {
      this.add( model );
    }
  }
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;
  }
1031363
private function generateModel($model){
        if(is_object($model))
            Session::set(md5(Request::getArea().Request::getController().Request::getAction()), base64_encode(get_class($model)));
    }
879860
function getProperties(model) {
    const modelName = model.constructor.name;
    const properties = typed_conversions_1.hashToArray(exports.propertiesByModel[modelName], "property") || [];
    let parent = Object.getPrototypeOf(model.constructor);
    while (parent.name) {
        const subClass = new parent();
        const subClassName = subClass.constructor.name;
        properties.push(...typed_conversions_1.hashToArray(exports.propertiesByModel[subClassName], "property"));
        parent = Object.getPrototypeOf(subClass.constructor);
    }
    return properties;
}
98866
function init (model) {
    if (model.__ttl) return;

    var distinct_ = model.distinct;
    model.distinct = function distinct (field, cond, cb) {
      applyTTL(cond);
      return distinct_.call(model, field, cond, cb);
    }

    'findOne find count'.split(' ').forEach(function (method) {
      var fn = model[method];

      model[method] = function (cond, fields, opts, cb) {
        if (!cond) {
          cond = {};
        } else if ('function' == typeof cond) {
          cb = cond;
          cond = {};
        }

        applyTTL(cond);
        return fn.call(model, cond, fields, opts, cb);
      }
    });

    'where $where'.split(' ').forEach(function (method) {
      var fn = model[method];
      model[method] = function () {
        var query = fn.apply(this, arguments)
          , cond = {};
        applyTTL(cond);
        return query.find(cond);
      }
    });

    if (reap) {
      model.startTTLReaper();
    }
  }
207710
function refreshModel(o) {
  if (!(o instanceof Model)) {throw new TypeError('Model expected')}
  _.forEach(o.elements(), refreshElement)
}
452957
private void applyDefinitionComponent(MarkupDocBuilder markupDocBuilder, String definitionName, Model model) {
        definitionComponent.apply(markupDocBuilder, DefinitionComponent.parameters(
                definitionName,
                model,
                2));
    }
66477
function bindModel(proc, model) {
  const actualModel = model || {};
  proc.model = actualModel;
  proc.logic.model = actualModel;

  if (!actualModel.__proc) {
    Object.defineProperty(actualModel, '__proc', {
      value: proc,
      enumerable: false,
      configurable: true
    });
  }
}
347555
private void prepareModel(DescriptorRepository model)
    {
        TreeMap result = new TreeMap();

        for (Iterator it = model.getDescriptorTable().values().iterator(); it.hasNext();)
        {
            ClassDescriptor classDesc = (ClassDescriptor)it.next();

            if (classDesc.getFullTableName() == null)
            {
                // not mapped to a database table
                continue;
            }

            String elementName        = getElementName(classDesc);
            Table  mappedTable        = getTableFor(elementName);
            Map    columnsMap         = getColumnsFor(elementName);
            Map    requiredAttributes = getRequiredAttributes(elementName);
            List   classDescs         = getClassDescriptorsMappingTo(elementName);

            if (mappedTable == null)
            {
                mappedTable = _schema.findTable(classDesc.getFullTableName());
                if (mappedTable == null)
                {
                    continue;
                }
                columnsMap         = new TreeMap();
                requiredAttributes = new HashMap();
                classDescs         = new ArrayList();
                _elementToTable.put(elementName, mappedTable);
                _elementToClassDescriptors.put(elementName, classDescs);
                _elementToColumnMap.put(elementName, columnsMap);
                _elementToRequiredAttributesMap.put(elementName, requiredAttributes);
            }
            classDescs.add(classDesc);
            extractAttributes(classDesc, mappedTable, columnsMap, requiredAttributes);
        }
        extractIndirectionTables(model, _schema);
    }
231094
function modelsToTypes(models) {
  let typeMap = models.filter(model => {
    if (_typeMap[model.modelName]) return false;
    return true;
  }).reduce((map, model) => {
    return (0, _assign2.default)(map, { [model.modelName]: toType(model) });
  }, {});
  _typeMap = (0, _assign2.default)(_typeMap, typeMap);

  // Deal with ref after all types are defined
  (0, _entries2.default)(typeMap).forEach(_ref => {
    var _ref2 = (0, _slicedToArray3.default)(_ref, 2);

    let modelName = _ref2[0];
    let type = _ref2[1];

    const originFileds = type._typeConfig.fields();
    const newTypeFileds = (0, _entries2.default)(originFileds).map(_ref3 => {
      var _ref4 = (0, _slicedToArray3.default)(_ref3, 2);

      let path = _ref4[0];
      let pathValue = _ref4[1];

      let newPathValue = (0, _assign2.default)({}, pathValue);
      if (newPathValue.ref) {
        const ref = newPathValue.ref;
        if (!_typeMap[ref]) throw TypeError(`${ref} is not a model`);
        const model = models.find(m => m.modelName === ref);
        const refModelType = _typeMap[ref];
        if (newPathValue.type instanceof _graphql.GraphQLList) {
          newPathValue = (0, _assign2.default)({}, newPathValue, {
            type: new _graphql.GraphQLList(refModelType),
            resolve: (() => {
              var _ref5 = (0, _asyncToGenerator3.default)(function* (instance) {
                // TODO: args filter
                return yield model.find({ _id: { $in: instance[path] } });
              });

              return function resolve(_x) {
                return _ref5.apply(this, arguments);
              };
            })()
          });
        } else {
          newPathValue = (0, _assign2.default)({}, newPathValue, {
            type: refModelType,
            resolve: (() => {
              var _ref6 = (0, _asyncToGenerator3.default)(function* (instance) {
                return yield model.findById(instance[path]);
              });

              return function resolve(_x2) {
                return _ref6.apply(this, arguments);
              };
            })()
          });
        }
      }
      return { [path]: newPathValue };
    }).reduce((typeField, path) => (0, _assign2.default)(typeField, path), {});

    typeMap[modelName]._typeConfig.fields = () => newTypeFileds;
  });

  _typeMap = (0, _assign2.default)(_typeMap, typeMap);
  return _typeMap;
}