Skip to content
This repository was archived by the owner on Aug 21, 2025. It is now read-only.

Update SortByField.php - #8

Open
brianteeman wants to merge 0 commit into
nikosdion-archive:mainfrom
brianteeman:main
Open

Update SortByField.php#8
brianteeman wants to merge 0 commit into
nikosdion-archive:mainfrom
brianteeman:main

Conversation

@brianteeman

Copy link
Copy Markdown

cast the value as SIGNED so that it sorts numerically
This is necessary because Joomla's custom fields are stored as strings, so a numeric field would sort alphabetically

Before this PR
1
11
111
2
3333
4

After this PR
1
2
4
11
111
3333

@nikosdion

Copy link
Copy Markdown
Collaborator

And how do you know that all fields everyone is going to use, on all sites they're using this plugin on are integers? In fact, the example I give in the README is a date field which is not an integer.

This is the problem with custom fields at the moment. They lack a method which would return the correct database expression to cast them into scalars for comparison, searching, etc. Lacking that, we can only assume they are stored as a JSON-encoded string which is sometimes not the case. You found one such case. There are other fields which store JSON objects or arrays. I cannot think of a good way you could deal with those fields.

@brianteeman

Copy link
Copy Markdown
Author

i came across this - maybe it will help others with the same problem

@nikosdion

Copy link
Copy Markdown
Collaborator

If you have some ideas about how an interface to select the cast (and subelement if object or array) I'd like to hear it. I can't promise it can be implemented, but it's better than me drawing a blank on how to handle those cases.

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants