@param Entity $entity
@param Select $query
@param array  $with
@param string $prefix

@return Select
352440
private function joinRelationsToQuery(Entity $entity, Select $query, array $with, $prefix = '')
    {
        if ($prefix === '') {
            $leftAlias = $this->alias ?: $entity->getTable();
        } else {
            $leftAlias = $prefix;
            $prefix .= '_';
        }

        foreach (array_filter($with, [$entity, 'hasRelation']) as $relationName) {
            $relation      = $entity->getRelation($relationName);
            $relatedEntity = $relation->getEntity();

            $alias = $prefix . $relationName;

            $query->addSelect(
                array_map(
                    function ($item) use ($alias) {
                        return "{$alias}.{$item} as {$alias}_{$item}";
                    },
                    array_values($relatedEntity->getFieldNames())
                )
            );

            $relation->joinToQuery($query, $leftAlias, $alias);

            $strippedWith = Utils::filterPrefixedElements($with, $relationName . '.', Utils::FILTER_REMOVE_PREFIX);
            $this->joinRelationsToQuery($relatedEntity, $query, $strippedWith, $alias);
        }

        return $query;
    }
230925
public function mergeToQuery(Select $query)
    {
        $query->join(
            $this->getKeyCondition(),
            $this->getQuery()->getWhere()->build(),
            null,
            $this->getQuery()->getBinds('where')
        );

        foreach ($this->select as $select) {
            $query->prependSelect($select);
        }

        foreach ($this->getQuery()->getSelect() as $key => $select) {
            $query->prependSelect([$key => $select]);
        }

        foreach ($this->getQuery()->getJoin() as $join) {
            $query->join($join, null, null, $this->getQuery()->getBinds('join', true));
        }

        if ($groupBy = $this->getQuery()->getGroupBy()) {
            $query->groupBy($groupBy);
        }

        if (($having = $this->getQuery()->getHaving()) && $having->hasChildren()) {
            $query->having($having);
        }

        if ($orderBy = $this->getQuery()->getOrderBy()) {
            $query->orderBy($orderBy);
        }

        return $this;
    }
463125
public function query($entity, $query)
	{
		$retValue = array();

		try{
			$m = new MongoDB\Driver\Manager($this->url);
			$bulk = new MongoDB\Driver\BulkWrite;

			$options = [];

			$mQuery = new \MongoDB\Driver\Query($query, $options);
			$mCol = $this->db . "."  . $entity;
			$jsonData = $m->executeQuery($mCol, $mQuery);

			$retValue = $jsonData->toArray();
		}
		catch(Exception $e) {
			$this->_log->addError($e->getMessage());
		}

		return $retValue;
	}
1104353
public function selectOne($tableName, $where = null, $afterWhere = '')
    {
        return $this->pdo->selectOne($tableName, $where, $afterWhere);
    }
1084284
public function selectSub($query, $as)
	{
		if ($query instanceof Closure)
		{
			$callback = $query;

			$callback($query = $this->newQuery());
		}

		if ($query instanceof Builder)
		{
			$bindings = $query->getBindings();

			$query = $query->toSql();
		}
		elseif (is_string($query))
		{
			$bindings = [];
		}
		else
		{
			throw new InvalidArgumentException;
		}

		return $this->selectRaw('('.$query.') as '.$this->grammar->wrap($as), $bindings);
	}
321474
public function getBy(array $where = [], array $with = [])
    {
        $query = $this->make($with);

        $query = $this->applyWhere($query, $where);

        return $query->get();
    }
722933
public static <T> JPQLQuery<T> selectFrom(EntityPath<T> expr) {
        return select(expr).from(expr);
    }
428991
public function scopeFiltersApply(Builder $query, $entity = null): Builder
    {
        if (! is_null($entity)) {
            try {
                $this->getEntity($entity);
            } catch (EntityTypeException $e) {
            }
        }

        return $this->filter($query);
    }
1334247
public function selectAsArray($withMaxPermissions = false, $withLastOpenDate = false)
    {
        $this->init();
        $this->resultAsArray = true;
        $this->joinSingleRelatives = true;
        $eol = PHP_EOL;
        $this->selectClause =
            "SELECT DISTINCT{$eol}".
            "    node.id as id,{$eol}".
            "    node.uuid as uuid,{$eol}".
            "    node.name as name,{$eol}".
            "    node.path as path,{$eol}".
            "    IDENTITY(node.parent) as parent_id,{$eol}".
            "    creator.username as creator_username,{$eol}".
            "    creator.id as creator_id,{$eol}".
            "    resourceType.name as type,{$eol}".
            "    icon.relativeUrl as large_icon,{$eol}".
            "    node.mimeType as mime_type,{$eol}".
            "    node.index as index_dir,{$eol}".
            "    node.creationDate as creation_date,{$eol}".
            "    node.modificationDate as modification_date,{$eol}".
            "    node.published as published,{$eol}".
            "    node.accessibleFrom as accessible_from,{$eol}".
            "    node.accessibleUntil as accessible_until,{$eol}".
            "    node.deletable as deletable{$eol}";

        if ($withMaxPermissions) {
            $this->leftJoinRights = true;
            $this->selectClause .= ",{$eol}rights.mask";
        }

        if ($withLastOpenDate) {
            $this->leftJoinLogs = true;
            $this->selectClause .= ",{$eol}log.dateLog as last_opened";
        }

        $this->selectClause .= $eol;

        return $this;
    }
49443
public function serialize(EntityContract $entity, Collection $select = null)
    {
        $bag = parent::serialize($entity, $select);
        $bag->set('url', $entity->getFullUrl());
        $bag->set('media', $entity->media->count() > 0 ? $entity->media[0]->toArray() : null);

        return $bag;
    }
76594
public function rawSelect(Query $query, $join = 'all')
        {
            if (!$query instanceof Query) {
                $query = new Query($this);
            }

            $query->setupJoinTables($join);
            $query->generateSelectSQL();

            $resultset = Statement::getPreparedStatement($query)->execute();
            return ($resultset->count()) ? $resultset : null;
        }
366558
public function selectSub($query, $as)
    {
        [$query, $bindings] = $this->createSub($query);

        return $this->selectRaw(
            '('.$query.') as '.$this->grammar->wrap($as), $bindings
        );
    }
1345803
public function find($entityName, $where = [], $joinConditions = [])
    {
        return $this->getRepository($entityName)->find($where, 'u', false, $joinConditions);
    }
1114669
protected function whereNullHandler($key, string $prefix = '', string $operator = ''): IQueryBuilderHandler
    {
        $key = $this->adapterInstance->wrapSanitizer($this->addTablePrefix($key));
        $prefix = ($prefix !== '') ? $prefix . ' ' : $prefix;

        return $this->{$operator . 'Where'}($this->raw("$key IS {$prefix}NULL"));
    }
846593
final protected function createSelectQuery(Query $query)
    {
        $select = $this->getDatabase()->select('node', 'n')->fields('n', ['nid'])->addTag('node_access');

        if ($this->addGroupby()) {
            $select->groupBy('n.nid');
        }

        return $select;
    }
422786
public function fieldSelect($table, $fields, $where, $orderBy = null)
    {
        $table = $this->getTableName($table);

        $query = "SELECT ";

        if (substr($this->mode, 0, 5) === "mssql") {
            $query .= "TOP 1 ";
        }

        $query .= $this->selectFields($fields);

        $query .= " FROM " . $table . " ";

        $params = null;
        if ($where !== self::NO_WHERE_CLAUSE) {
            $query .= "WHERE " . $this->where($where, $params);
        }

        if ($orderBy) {
            $query .= $this->orderBy($orderBy) . " ";
        }

        switch ($this->mode) {

            case "mysql":
            case "postgres":
            case "redshift":
            case "sqlite":
                $query .= "LIMIT 1";
                break;

            case "odbc":
                $query .= "FETCH FIRST 1 ROW ONLY";
                break;
        }

        return $this->query($query, $params)->fetch();
    }
898304
public function selectOne( $query, $bindings = [] )
	{
		$query = $this->bind_params( $query, $bindings );

		$result = $this->db->get_row( $query );

		if ( $result === false || $this->db->last_error ) {
			throw new QueryException( $query, $bindings, new \Exception( $this->db->last_error ) );
		}

		return $result;
	}