filament icon indicating copy to clipboard operation
filament copied to clipboard

Select relationship orderBy is without function

Open pxlrbt opened this issue 3 years ago • 2 comments

Package

filament/forms

Package Version

v2.0.0

Laravel Version

all

Livewire Version

all

PHP Version

all

Problem description

Select field orders items by $displayTitleColumn. But as the primary key is usually an integer, the order gets lost when returning the JSON.

For example:

Route::get('/test', fn () => [
    2 => 'N2',
    1 => 'N1',
]);

will result in:

{
  "1": "N1",
  "2": "N2"
}

We would need to wrap every result in an array to prevent this.

Expected behavior

Correctly ordered results.

Steps to reproduce

Select::make()->relationship()

Reproduction repository

No response

Relevant log output

No response

pxlrbt avatar Jul 27 '22 18:07 pxlrbt

I guess this is a js specific notion, see https://www.stefanjudis.com/today-i-learned/property-order-is-predictable-in-javascript-objects-since-es2015/, and ideas here https://stackoverflow.com/questions/69946683/can-i-preserve-the-order-of-a-javascript-objects-entries-when-some-entry-keys

simonbuehler avatar Jul 28 '22 21:07 simonbuehler

So dan mentioned could prefix all the IDs and then strip that back in the mutate before save. lets maybe document that workaround here until we have a full solution? I will see what i can throw together if someone else doesn't beat me to it.

MACscr avatar Aug 01 '22 19:08 MACscr