protected function sortQuery(Builder $query, array $sort_order_options, Model $temp_instance, array $columns)
	{
		$allowed_directions = [
			'ASC',
			'DESC',
		];

		foreach ($sort_order_options as $order_by => $direction) {
			if (in_array(strtoupper($direction), $allowed_directions)) {
				$split = explode(self::GLUE, $order_by);

				// Sorts deeper than the depth restriction + 1 are not allowed
				// Depth restriction is offset by 1 because sorts terminate with a column
				// i.e. 'users.posts.title' => 'asc' but the depth we expect is 'users.posts'
				if (count($split) > ($this->getDepthRestriction() + 1)) {
					// Unset the disallowed sort
					unset($sort_order_options[$order_by]);
					continue;
				}

				if (in_array($order_by, $columns)) {
					$query->orderBy($order_by, $direction);
				} else {
					// Pull out orderBy field
					$field = array_pop($split);

					// Select only the base table fields, don't select relation data. Desired relation data
					// should be explicitly included
					$base_table = $temp_instance->getTable();
					$query->selectRaw("$base_table.*");

					$this->applyNestedJoins($query, $split, $temp_instance, $field, $direction);
				}
			}
		}
	}