### Model Query
Make the call to the Model layer
@param {Object} options
@returns {Object} options
966112
function doQuery(options) {
            return models.Tag.findPage(options)
                .then(({data, meta}) => {
                    return {
                        tags: data.map(model => urlsForTag(model.id, model.toJSON(options), options)),
                        meta: meta
                    };
                });
        }
703946
function parseFindOptions(model, options, expectSingleResult) {
    var select, where, params, append, limit, offset;
    if (options.select) {
        if (Array.isArray(options.select)) {
            select = _.map(options.select, function (f) {
                return '`' + f + '`';
            }).join(', ');
        } else {
            select = options.select;
        }
    } else {
        select = model.__selectAttributesNames;
    }

    where = options.where || '';
    params = options.params || [];
    append = '';

    if (options.order) {
        append = append + ' order by ' + options.order;
    }
    limit = options.limit;
    offset = options.offset;

    if (limit === undefined && expectSingleResult) {
        limit = 2;
    }

    if (limit && offset) {
        append = append + ' limit ' + offset + ',' + limit;
    } else {
        if (limit) {
            append = append + ' limit ' + limit;
        }
        if (offset) {
            append = append + ' limit ' + offset + ',2147483647';
        }
    }
    return {
        select: select,
        where: where,
        params: params,
        append: append
    };
}
819601
function(options) {
        var self = this;

        var params = this.toJSON();
        params.limit = 1;
        var request = this._createRequest(params, options);

        return request.then(function(response) {
          return _.map(response.results, function(json) {
            var obj = self._newObject();
            if (obj._finishFetch) {
              obj._finishFetch(self._processResult(json), true);
            }
            return obj;
          })[0];
        });
      }
66505
function doQuery(options) {
            return models.Tag.add(options.data.tags[0], _.omit(options, ['data']))
                .then((model) => {
                    return {
                        tags: [urlsForTag(model.id, model.toJSON(options), 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;
    }
1014874
function(models, options) {
      var singular = !Array.isArray(models);
      models = singular ? [models] : models.slice();
      options || (options = {});
      for (var i = 0, length = models.length; i < length; i++) {
        var model = models[i] = this.get(models[i]);
        if (!model) continue;
        var id = this.modelId(model.attributes);
        if (id != null) delete this._byId[id];
        delete this._byId[model.cid];
        var index = this.indexOf(model);
        this.models.splice(index, 1);
        this.length--;
        if (!options.silent) {
          options.index = index;
          model.trigger('remove', model, this, options);
        }
        this._removeReference(model, options);
      }
      return singular ? models[0] : models;
    }
818995
function(req) {

    // Ensure a model can be deduced from the request options.
    var model = req.options.model || req.options.controller;
    if (!model) {
      throw new Error('No "model" specified in route options.');
    }

    var Model = req._sails.models[model];
    if (!Model) {
      throw new Error('Invalid route option, "model". No model named: ' + model);
    }

    return Model;
  }
941087
function(models, options) {
      models  || (models = []);
      options || (options = {});
      this.each(this._removeReference);
      this._reset();
      this.add(models, {silent: true});
      if (!options.silent) this.trigger('reset', this, options);
      return this;
    }
857736
function getModel(req, res, next, model) {
		var fullModel = Rhapsody.requireModel(model, true);

		if(!fullModel) {
			Rhapsody.log.verbose('Nonexistent model', 'Couldn\'t find collection %s.', model);
			return responseUtils.respond(res, 400); //Malformed syntax or a bad query
		}

		//This model does not allow REST API
		if(!fullModel.options.allowREST) {
			return responseUtils.respond(res, 404);
		}

		req.fullModel = fullModel;

		next();
	}
611757
function (opts) {
        var layerName = opts.name,
            layer = null

        this.children.forEach(function (item) {
            if (item instanceof TMXLayer && item.layerName == layerName) {
                layer = item
            }
        })
        if (layer !== null) {
            return layer
        }
    }
621984
function(models, options) {
      if (_.isArray(models)) {
        for (var i = 0, l = models.length; i < l; i++) {
          this._remove(models[i], options);
        }
      } else {
        this._remove(models, options);
      }
      return this;
    }
1208206
function doQuery(options) {
            return models.User.findOne(options.data, _.omit(options, ['data']))
                .then((model) => {
                    if (!model) {
                        return Promise.reject(new common.errors.NotFoundError({
                            message: common.i18n.t('errors.api.users.userNotFound')
                        }));
                    }

                    return {
                        users: [urlsForUser(model.id, model.toJSON(options), options)]
                    };
                });
        }
693127
function paginate(q, options, callback) {
    var model = this;

    options = options || {};
    callback = callback || function() {};

    var page = options.page || 1;
    var limit = options.limit || 10;
    var columns = options.columns || null;
    var sortBy = options.sortBy || null;
    var populate = options.populate || null;
    var lean = options.lean || false;
    var skip = (page * limit) - limit;

    var query = model.find(q);
    if (columns !== null) {
        query = query.select(columns);
    }
    query = query.skip(skip).limit(limit);
    if (sortBy !== null) {
        query.sort(sortBy);
    }
    if (populate) {
        if (Array.isArray(populate)) {
            populate.forEach(function(field) {
                query = query.populate(field);
            });
        } else {
            query = query.populate(populate);
        }
    }
    if (lean) {
        query.lean();
    }

    async.parallel({
        results: function(callback) {
            query.exec(callback);
        },
        count: function(callback) {
            model.count(q, function(err, count) {
                callback(err, count);
            });
        }
    }, function(error, data) {
        if (error) {
            return callback(error);
        }
        callback(null, data.results, data.count, Math.ceil(data.count / limit) || 1);
    });
}
951071
function(model, options) {
    options = options ? _.clone(options) : {};
    if (!(model = this._prepareModel(model, options))) return false;
    if (!options.wait) this.add(model, options);
    return this._callAdapter('addToIndex', options, model);
  }
853240
function(models, options) {
      if (_.isArray(models)) {
        for (var i = 0, l = models.length; i < l; i++) {
          this._add(models[i], options);
        }
      } else {
        this._add(models, options);
      }
      return this;
    }
992924
function ImmutableCoreModelQuery (args) {
    // require model
    this.assert(defined(args.model) && args.model.ImmutableCoreModel, 'model required')
    // set model for query
    this.model = args.model
    // args and session are both optional in some cases
    this.args = _.cloneDeep( requireValidOptionalObject(args.args) )
    this.session = requireValidOptionalObject(args.session)
    // validate and normalize args
    this.initArgs()
    // valid view args and instantiate model view engine if there are views
    this.initViews()
}
895716
function doQuery(options) {
            return models.User.transferOwnership(options.data.owner[0], _.omit(options, ['data']))
                .then((models) => {
                    return {
                        users: models.toJSON(_.omit(options, ['data']))
                    };
                });
        }