statamic / eloquent-driver

Provides support for storing your Statamic data in a database, rather than flat files.
https://statamic.dev/tips/storing-content-in-a-database
MIT License
104 stars 73 forks source link

Only save custom sort field and direction #138

Closed ryanmitchell closed 1 year ago

ryanmitchell commented 1 year ago

@robdekort found a lovely bug that when you have a dated collection and make it order able it wasn't honouring the order you set. So this fix changes it by not saving the sortField to the database when the collection is orderable.

jasonvarga commented 1 year ago

We should only save sortField (and sortDirection) if it's a custom value.

By leaving it blank, it'll apply the appropriate logic.

The custom value would be in the property. We could probably add a method to the Collection class like customSortField and then change this line to 'sort_field' => $source->customSortField().

jasonvarga commented 1 year ago

In order for this fix to be reflected, you'll need get rid of the custom sort field and direction.

You can run php artisan tinker and run this for each collection, substituting the collection handle appropriately.

\Statamic\Eloquent\Collections\CollectionModel::where('handle', 'your_collection')->update([
  'settings->sort_field' => null,
  'settings->sort_dir' => null,
]);

Or, put it in a migration.