helper function to populate a Waterline query according to the model definition include -> record
@param  {[type]} query        [description]
@param  {[type]} associations [description]
@return {[type]}              [description]
773465
function ( query, associations ) {
		_.each( associations, function ( assoc ) {
			// if the associations is to be populated with the full records...
			if ( assoc.include === "record" ) query.populate( assoc.alias );
		} );
		return query;
	}
1130138
def _query_select_options(self, query, select_columns=None):
        
        if select_columns:
            _load_options = list()
            for column in select_columns:
                if "." in column:
                    model_relation = self.get_related_model(column.split(".")[0])
                    if not self.is_model_already_joinded(query, model_relation):
                        query = query.join(model_relation)
                    _load_options.append(
                        Load(model_relation).load_only(column.split(".")[1])
                    )
                else:
                    if not self.is_relation(column) and not hasattr(
                        getattr(self.obj, column), "__call__"
                    ):
                        _load_options.append(Load(self.obj).load_only(column))
                    else:
                        _load_options.append(Load(self.obj))
            query = query.options(*tuple(_load_options))
        return query
156565
function modelQuery(options) {
            return models.Post.findPage(options)
                .then(({data, meta}) => {
                    return {
                        posts: data.map(model => urlsForPost(model.id, model.toJSON(options), options)),
                        meta: meta
                    };
                });
        }
809717
function current (args) {
    // build args
    var queryArgs = {
        current: true,
        limit: 1,
        where: {
            id: this.id,
        },
        session: this.session,
    }
    // override with args if passed
    if (defined(args)) {
        _.merge(queryArgs, args)
    }
    // do query for current record
    return this.model.query(queryArgs)
}
833724
def run_query(self, query):
        
        collection = self.ds.connection(self.collection_name)

        cursor = collection.find(query)
        if cursor.count() == 0:
            raise LookupError('Collection {0} has no {1} records'
                              .format(self.collection_name, self.model_klass.__name__))
        return [self.model_klass.from_json(entry) for entry in cursor]
85798
function (model) {
            //if we have them return them;
            if (this.associationLoaded(model)) {
                var assoc = this.getAssociation(model);
                return this.isEager() ? assoc : when(assoc);
            } else if (model.isNew) {
                return null;
            } else {
                return this.fetch(model);
            }
        }
484540
def sparql_query(self, query, flush=None, limit=None):
        
        return self.find_statements(query, language='sparql', type='tuples',
            flush=flush, limit=limit)
16288
function (query, indexName) {
        var model = this.collection.get(query, indexName);
        if (model && includes(this.models, model)) return model;
    }
1080469
function getMatchingRecord(relationship, included, parents) {
        var circular, match;

        circular = findWhere(
            parents,
            {
                id: relationship.id,
                type: relationship.type
            }
        );

        if (circular) {
            return relationship;
        }

        var key = relationship.type + '-' + relationship.id;
        match = included[key];

        // IF: No match or match is the same as parent, return the relationship information
        if (!match) {
            return relationship;
        }

        populateRelatedFields(match, included, parents);

        // IF: relationship defined meta, merge with record provided meta
        var contextSpecificMeta = {};
        if (relationship && isObject(relationship.meta)) {
            contextSpecificMeta = extend({}, match.meta, relationship.meta);
        }

        return flatten(match, contextSpecificMeta);
    }
657696
function getCollectionsCompact(forEntity, includeNew) {
  let associations = forEntity.getMeta().fetch('associations');
  let collections  = {};

  Object.getOwnPropertyNames(associations).forEach(index => {
    let association = associations[index];

    if (association.type !== 'collection') {
      return;
    }

    collections[index] = [];
    if (!Array.isArray(forEntity[index])) {
      return;
    }

    forEntity[index].forEach(entity => {
      if (typeof entity === 'number') {
        collections[index].push(entity);

        return;
      }

      if (!(entity instanceof Entity)) {
        return;
      }

      if (entity.getId()) {
        collections[index].push(entity.getId());

        return;
      }

      if (includeNew) {
        collections[index].push(entity);

        return;
      }
    });
  });

  return collections;
}
537728
private Query createAccessControlledQuery(QueryModel queryModel) {
        Criteria criteria = getCurrentSession().createCriteria(persistentClass);

        for (String associationPath : queryModel.getAssociationConditions().keySet()) {
            criteria.createCriteria(associationPath);
        }

        CriteriaQueryTranslator criteriaQueryTranslator = new CriteriaQueryTranslator((SessionFactoryImplementor) sessionFactory,
                                                                                      (CriteriaImpl) criteria,
                                                                                      persistentClass.getName(),
                                                                                      CriteriaQueryTranslator.ROOT_SQL_ALIAS);

        StringBuilder queryStringBuilder = new StringBuilder();

        buildSelectClause(queryStringBuilder, criteriaQueryTranslator, queryModel.getAssociationConditions().keySet());

        List<TypedValue> parameters = buildWhereClause(queryStringBuilder, queryModel, criteria, criteriaQueryTranslator);

        if ((queryModel.getAssociationConditions() == null || queryModel.getAssociationConditions().isEmpty())
            && (queryModel.getSorts() == null || queryModel.getSorts().isEmpty())) {
            buildDefaultOrderClause(queryStringBuilder);
        } else {
            // can't use the default ordering by "ace.id" because of "select distinct..." syntax
            buildOrderClause(queryStringBuilder, queryModel, criteria, criteriaQueryTranslator);
        }

        Query query = getCurrentSession().createQuery(queryStringBuilder.toString());

        setParameters(parameters, query, queryModel.getAccessControlContext());

        return query;
    }
1007191
function query (args) {
    // add session if not set
    if (!args.session) {
        args.session = this.session
    }
    // return original method call
    return this.model.query(args)
}
98448
def _one_to_many_query(cls, query_obj, search4, model_attrib):
        
        model = model_attrib.parent.class_

        already_joined_tables = [mapper.class_ for mapper in query_obj._join_entities]

        if isinstance(search4, (str, int, Iterable)) and model not in already_joined_tables:
            query_obj = query_obj.join(model)

        if isinstance(search4, str):
            query_obj = query_obj.filter(model_attrib.like(search4))

        elif isinstance(search4, int):
            query_obj = query_obj.filter(model_attrib == search4)

        elif isinstance(search4, Iterable):
            query_obj = query_obj.filter(model_attrib.in_(search4))

        return query_obj
818682
def _joinOnAsPriv(self, model, onIndex, whatAs):
        
        if self._join:
            raise Exception("Already joined with a table!")

        self._join = model
        self._joinedField = whatAs
        table = model.table
        self._query = self._query.eq_join(onIndex, r.table(table))
        return self
1093033
public ResourceIterator<Relationship> findAssociation(GraphDatabaseService executionEngine, Object[] columnValues, String role, AssociationKeyMetadata associationKeyMetadata) {
		String query = getFindAssociationQuery( role, associationKeyMetadata );
		Map<String, Object> params = params( columnValues );
		executionEngine.execute( query, params );
		return executionEngine.execute( query, params( columnValues ) ).columnAs( "r" );
	}
486797
def base_query
      query = ActionLog
              .where(visibility: %w(public-only all))
              .where(organization: options.fetch(:organization))

      query = query.where(user: options[:user]) if options[:user]

      query = filter_follows(query)

      query
    end
1261303
function Query(state, entity) {
        /**
         * Primary key ids to filter records by. It is used for filtering records
         * direct key lookup when a user is trying to fetch records by its
         * primary key.
         *
         * It should not be used if there is a logic which prevents index usage, for
         * example, an "or" condition which already requires a full scan of records.
         */
        this.idFilter = null;
        /**
         * Whether to use `idFilter` key lookup. True if there is a logic which
         * prevents index usage, for example, an "or" condition which already
         * requires full scan.
         */
        this.cancelIdFilter = false;
        /**
         * Primary key ids to filter joined records. It is used for filtering
         * records direct key lookup. It should not be cancelled, because it
         * is free from the effects of normal where methods.
         */
        this.joinedIdFilter = null;
        /**
         * The where constraints for the query.
         */
        this.wheres = [];
        /**
         * The has constraints for the query.
         */
        this.have = [];
        /**
         * The orders of the query result.
         */
        this.orders = [];
        /**
         * Number of results to skip.
         */
        this.offsetNumber = 0;
        /**
         * Maximum number of records to return.
         *
         * We use polyfill of `Number.MAX_SAFE_INTEGER` for IE11 here.
         */
        this.limitNumber = Math.pow(2, 53) - 1;
        /**
         * The relationships that should be eager loaded with the result.
         */
        this.load = {};
        this.rootState = state;
        this.state = state[entity];
        this.entity = entity;
        this.model = this.getModel(entity);
        this.module = this.getModule(entity);
        this.hook = new Hook(this);
    }