You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
I have a custom sort that orders by a relationship value (localized title that is in a Metadata model/table), works fine until I start paginating with cursor pagination.
Originally I was ordering on a select in the orderBy, similar to the example in the spatie docs with StringLengthSort, but that does not work with CursorPaginator because it analyzes the ORDER BY clauses to be used as WHERE clauses when using a cursor, and it only accepts strings (i.e. column names).
I tried adding a SELECT (title FROM metadata WHERE...) as metadata_title and then ORDER BY metadata_title but that does not work because MySQL can not use WHERE on such a 'fake' column.
And I also tried adding a leftJoin('metadata', ...) but that messes up the Eloquent relationship loading.
I know it's quite a generic problem, but because this package works so nice for many other aspects I am hoping someone has been dealing with a similar issue and found a solution.
reacted with thumbs up emoji reacted with thumbs down emoji reacted with laugh emoji reacted with hooray emoji reacted with confused emoji reacted with heart emoji reacted with rocket emoji reacted with eyes emoji
-
I have a custom sort that orders by a relationship value (localized title that is in a
Metadata
model/table), works fine until I start paginating with cursor pagination.Originally I was ordering on a select in the orderBy, similar to the example in the spatie docs with
StringLengthSort
, but that does not work with CursorPaginator because it analyzes theORDER BY
clauses to be used asWHERE
clauses when using a cursor, and it only accepts strings (i.e. column names).I tried adding a
SELECT (title FROM metadata WHERE...) as metadata_title
and thenORDER BY metadata_title
but that does not work because MySQL can not use WHERE on such a 'fake' column.And I also tried adding a
leftJoin('metadata', ...)
but that messes up the Eloquent relationship loading.I know it's quite a generic problem, but because this package works so nice for many other aspects I am hoping someone has been dealing with a similar issue and found a solution.
Beta Was this translation helpful? Give feedback.
All reactions