Initialize primary keys only

@param string $constraints
@param string $joins
@param string $sorting
503375
protected function initKeys($constraints = '', $joins = '', $sorting = '')
    {
        $this->items = [];

        $query = implode(' ', [
            'SELECT t0.`'
            . $this->adapter->getSchema($this->table, 'primary')
            . '` FROM', '`'
            . $this->table
            . '` AS t0'
        ]);

        $rows = $this->adapter->getDriver()->query($query . $joins . $constraints . $sorting)->fetchAll();

        if (is_array($rows)) {
            $this->items = array_flip($rows);
        }
    }
576827
public function sort(array &$methods, $sort = self::BY_COMPLEXITY)
    {
        if (!in_array($sort, self::SORTS, true)) {
            $sort = self::BY_COMPLEXITY;
        }

        usort(
            $methods,
            $sort === self::BY_COMPLEXITY
                ? $this->byComplexity()
                : $this->byName()
        );
    }
1010601
protected function prepareJoins($joins) {
        $_joins = [];
        if ($joins) {
            foreach ($joins as $join) {
                $table     = $this->dialect->getTableName($join [0]);
                $alias     = empty ($join [3]) ? $table : $join [3];
                $_joins [] = [$table, $join [1], $join [2], $alias];
            }
        }

        return $_joins;
    }
839428
public function addJoins(Join ...$joins): MutableQuery
    {
        $cloned = clone $this;

        $activeJoins = iterator_to_array($this->joins);
        $activeJoins = array_merge($activeJoins, $joins);

        $cloned->joins = new JoinCollection(...$activeJoins);

        return $cloned;
    }
884330
protected function cacheResults(array $results)
    {
        $mapper = $this->mapper;

        // When hydrating EmbeddedValue object, they'll likely won't
        // have a primary key set.
        if ($mapper->getEntityMap()->getKeyName() !== null) {
            $mapper->getEntityCache()->add($results);
        }
    }
954272
public function joins(array $joins, $context) {
		$result = null;

		foreach ($joins as $key => $join) {
			if ($result) {
				$result .= ' ';
			}
			$join = is_array($join) ? $this->_instance('query', $join) : $join;
			$options['keys'] = ['mode', 'source', 'alias', 'constraints'];
			$result .= $this->renderCommand('join', $join->export($this, $options));
		}
		return $result;
	}
1070798
public function buildDSRetrievalSQL($data, &$joins, &$where, $andOperation = false)
    {
        $field_id = $this->get('id');

        if (self::isFilterRegex($data[0])) {
            $this->buildRegexSQL($data[0], array('value'), $joins, $where);
        } elseif (self::isFilterSQL($data[0])) {
            $this->buildFilterSQL($data[0], array('value'), $joins, $where);
        } else {
            if (is_array($data)) {
                $data = $data[0];
            }

            $this->_key++;
            $data = $this->cleanValue($data);
            $joins .= "
                LEFT JOIN
                    `tbl_entries_data_{$field_id}` AS t{$field_id}_{$this->_key}
                    ON (e.id = t{$field_id}_{$this->_key}.entry_id)
            ";
            $where .= "
                AND MATCH (t{$field_id}_{$this->_key}.value) AGAINST ('{$data}' IN BOOLEAN MODE)
            ";
        }

        return true;
    }
1328552
public function addConstraints()
    {
        $localValue = $this->farParent[$this->localKey];

        $this->performJoin();

        if (static::$constraints) {
            $this->query->where($this->getQualifiedFirstKeyName(), '=', $localValue);
        }
    }
973213
public function orderByRaw(string $sql, array $bindings = []): BaseQueryRelateContract
    {
        $this->query->orderByRaw($sql, $bindings);

        return $this;
    }
154619
protected function compileOneJoin(Join $join, array &$bindings): string
    {
        $sql = $join->type.' JOIN '.$this->compileIdentifierWithAlias($join->table, $join->tableAlias, $bindings);

        if ($join->criteria) {
            $sql .= ' ON '.$this->compileCriteria($join->criteria, $bindings);
        }

        return $sql;
    }
832411
public function sort(Sorting $sorting)
	{
		if (is_callable($sorting->getSortCallback())) {
			call_user_func(
				$sorting->getSortCallback(),
				$this->data_source,
				$sorting->getSort()
			);

			return $this;
		}

		$sort = $sorting->getSort();

		if (!empty($sort)) {
			$this->data_source->getSqlBuilder()->setOrder([], []);

			foreach ($sort as $column => $order) {
				$this->data_source->order("$column $order");
			}
		} else {
			/**
			 * Has the statement already a order by clause?
			 */
			if (!$this->data_source->getSqlBuilder()->getOrder()) {
				$this->data_source->order($this->primary_key);
			}
		}

		return $this;
	}
1365740
private function mapOrdering(MemberOrdering $ordering, Select $select, array $memberMappings)
    {
        $mapping = $memberMappings[$ordering->getNestedMember()->asString()];

        $mapping->getMapping()
            ->addOrderByToSelect($select, $mapping->getLastTableAlias(), $ordering->isAsc());
    }
526356
public function sortSecondaryKeys($primaryKey, array $order = null)
    {
        if (!isset($this->values[$primaryKey])) {
            throw new OutOfBoundsException(sprintf(
                'The key "%s" does not exist.',
                $primaryKey
            ));
        }

        if (!$order) {
            ksort($this->values[$primaryKey]);

            return;
        }

        $orderedKeys = array_intersect_key(array_flip($order), $this->values[$primaryKey]);

        $this->values[$primaryKey] = array_replace($orderedKeys, $this->values[$primaryKey]);
    }
122477
protected function cacheRelation($results, $relation)
    {
        $cache = $this->parentMapper->getEntityCache();

        $cache->cacheLoadedRelationResult($this->parent->getEntityKeyName(), $relation, $results, $this);
    }
626196
private function formJoin($query, $parentTable, $relatedTable, $parentPrimaryKey, $relatedPrimaryKey)
    {
        $joinType = config('columnsortable.join_type', 'leftJoin');

        return $query->select($parentTable.'.*')->{$joinType}($relatedTable, $parentPrimaryKey, '=', $relatedPrimaryKey);
    }
840972
public function scopePimp(Builder $builder, $query = [], $sort = [], $relations = [])
    {
        $query = $query ?: array_except(Input::all(), [$this->sortParameterName, $this->withParameterName]);
        $builder->filtered($query)->sorted($sort)->withRelations($relations);
    }
603096
public function addEagerConstraints(array $results)
    {
        $this->query->whereIn($this->foreignKey, $this->getKeysFromResults($results, $this->localKey));
    }