rsanchez / Deep

A set of Eloquent models for ExpressionEngine Channel Entries.
http://rsanchez.github.io/Deep/
MIT License
51 stars 14 forks source link

Is it possible to sort a query by a file fields exif values? #23

Closed tobz-nz closed 9 years ago

tobz-nz commented 9 years ago

I have a channel with a file field, I'd like to sort the entries by the [size/type/date] of a file in that field. Not sure if that's possible of not?

I know it's possible to sort the collection after the fact, the problem is that it's a paginated query; so that wouldn't work.

Any ideas?

rsanchez commented 9 years ago

I think you'd have to do this:

$entries = Entries::channel('products')
    ->join(
        'files',
        DB::raw("CONCAT('{filedir_', exp_files.upload_location_id, '}', exp_files.file_name)"),
        '=',
        'field_id_12'
    )
    ->orderBy('files.file_size', 'desc') // or files.mime_type or files.upload_date
    ->get();
tobz-nz commented 9 years ago

Yeah this worked after a fashion. Had a related issue with deuplicate files in in files table which threw me for a while. Doing a sync in EE sorted that out.

Thanks for the suggestion.