Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[10.x] Get the key name through getScoutKeyName() on the Database engine #843

Merged
merged 1 commit into from
Jul 2, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 5 additions & 5 deletions src/Engines/DatabaseEngine.php
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,7 @@ public function paginateUsingDatabase(Builder $builder, $perPage, $pageName, $pa
}
})
->when(! $this->getFullTextColumns($builder), function ($query) use ($builder) {
$query->orderBy($builder->model->getKeyName(), 'desc');
$query->orderBy($builder->model->getScoutKeyName(), 'desc');
})
->paginate($perPage, ['*'], $pageName, $page);
}
Expand Down Expand Up @@ -127,7 +127,7 @@ public function simplePaginateUsingDatabase(Builder $builder, $perPage, $pageNam
}
})
->when(! $this->getFullTextColumns($builder), function ($query) use ($builder) {
$query->orderBy($builder->model->getKeyName(), 'desc');
$query->orderBy($builder->model->getScoutKeyName(), 'desc');
})
->simplePaginate($perPage, ['*'], $pageName, $page);
}
Expand All @@ -152,7 +152,7 @@ protected function searchModels(Builder $builder, $page = null, $perPage = null)
}
})
->when(! $this->getFullTextColumns($builder), function ($query) use ($builder) {
$query->orderBy($builder->model->getKeyName(), 'desc');
$query->orderBy($builder->model->getScoutKeyName(), 'desc');
})
->get();
}
Expand Down Expand Up @@ -198,7 +198,7 @@ protected function initializeSearchQuery(Builder $builder, array $columns, array
$canSearchPrimaryKey = ctype_digit($builder->query) &&
in_array($builder->model->getKeyType(), ['int', 'integer']) &&
($connectionType != 'pgsql' || $builder->query <= PHP_INT_MAX) &&
in_array($builder->model->getKeyName(), $columns);
in_array($builder->model->getScoutKeyName(), $columns);

if ($canSearchPrimaryKey) {
$query->orWhere($builder->model->getQualifiedKeyName(), $builder->query);
Expand All @@ -214,7 +214,7 @@ protected function initializeSearchQuery(Builder $builder, array $columns, array
$this->getFullTextOptions($builder)
);
} else {
if ($canSearchPrimaryKey && $column === $builder->model->getKeyName()) {
if ($canSearchPrimaryKey && $column === $builder->model->getScoutKeyName()) {
continue;
}

Expand Down