Skip to content

Commit

Permalink
fix: separate sort and search fields when looking up relationsip.
Browse files Browse the repository at this point in the history
  • Loading branch information
andershermansen committed Apr 23, 2024
1 parent 9152a23 commit 9f33d74
Showing 1 changed file with 7 additions and 8 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -146,13 +146,12 @@ const Relationship: React.FC<Props> = (props) => {

if (resultsFetched < 10) {
const collection = collections.find((coll) => coll.slug === relation)
let fieldToSearch = collection?.defaultSort || collection?.admin?.useAsTitle || 'id'
if (!searchArg) {
if (typeof sortOptions === 'string') {
fieldToSearch = sortOptions
} else if (sortOptions?.[relation]) {
fieldToSearch = sortOptions[relation]
}
const fieldToSearch = collection?.admin?.useAsTitle || 'id'
let fieldToSort = collection?.defaultSort || 'id'
if (typeof sortOptions === 'string') {
fieldToSort = sortOptions
} else if (sortOptions?.[relation]) {
fieldToSort = sortOptions[relation]
}

const query: {
Expand All @@ -164,7 +163,7 @@ const Relationship: React.FC<Props> = (props) => {
limit: maxResultsPerRequest,
locale,
page: lastLoadedPageToUse,
sort: fieldToSearch,
sort: fieldToSort,
where: {
and: [
{
Expand Down

0 comments on commit 9f33d74

Please sign in to comment.