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
108 stars 76 forks source link

When a collection is orderable, use that order #95

Closed ryanmitchell closed 1 year ago

ryanmitchell commented 1 year ago

As reported over on Discord the orderable collection view doesn't default to order sorting.

So by default we need to save the sort_field as order in the database for these collections.

what-the-diff[bot] commented 1 year ago
jasonvarga commented 1 year ago

I think I noticed it was because title was being saved to the settings for sort_field. If nothing was saved, it would have worked fine. I think it happened during import.

The logic should be, if there's a sort field, use that.

https://github.com/statamic/cms/blob/5af6b5fa9c6b38cc8a30f595a1b510fb9245d13b/src/Entries/Collection.php#L143-L151

ryanmitchell commented 1 year ago

Hmm, I noticed on a site we didn't do any imports from (set up collections in eloquent). Its being saved to the DB here: https://github.com/statamic/eloquent-driver/blob/85020494c573a6b2d0fc22c31351522defa7ade6/src/Collections/Collection.php#L33 and ours was saved as 'title' too.

jasonvarga commented 1 year ago

Ok not the importer then, but somewhere. 😄

ryanmitchell commented 1 year ago

Should we just not be saving sortField?

jasonvarga commented 1 year ago

Maybe we should only save it if it's "custom". ie not order for orderable collections, not date for date collections, or title. (Following the logic of the line I linked to before)

On the file driver, it doesn't get saved - because there's not even a field for it on the collection config screen. The only way to customize it is to put it in the yaml.

ryanmitchell commented 1 year ago

Oh maybe it’s just my error in saving it in the first place. I think we should just not save it and let the default behaviour happen.