awesome_hstore_translate icon indicating copy to clipboard operation
awesome_hstore_translate copied to clipboard

Sorting

Open nathansamson opened this issue 7 years ago • 9 comments

Does the system allow for easy ordering?

eg. order(name: :asc) where name is a translated field? How well does it combine with fallbacks?

I did not see anything in the documentation, nor did I see anything in the code that would support this on first sight

Would it be hard to implement?

nathansamson avatar Nov 23 '16 17:11 nathansamson

Thank you for creating the issue.

Sorting is not implemented, but it shouldn't be hard to do so. I'll have a look into it this weekend.

openscript avatar Nov 24 '16 09:11 openscript

I've implemented sorting. Please check it out.

openscript avatar Feb 03 '17 11:02 openscript

Hi,

Thanks for sorting this out (pun not intended).

Note that I have rolled out our own implementation based on JSON(B) which also implements fallbacks in sorting.

nathansamson avatar Feb 03 '17 13:02 nathansamson

The 0.3 release breaks order calls without a sorting direction. e.g. order(:position):

NoMethodError: private method `select' called for :position:Symbol

daniel-rikowski avatar Feb 03 '17 13:02 daniel-rikowski

@daniel-rikowski I'll fix that in a second.

openscript avatar Feb 03 '17 14:02 openscript

Sorry about that.

openscript avatar Feb 03 '17 14:02 openscript

@daniel-rikowski I've pushed another version.

Probably I'll also switch over to a json solution, due it's more handy if you need to deliver json through a api anyway.

openscript avatar Feb 03 '17 15:02 openscript

Thank you!

Symbols do work now, but combinations still do not, e.g.

Model.order(:position, id: :desc)

This results in a call like order(position: :asc, { id: :desc } => :asc }

Strings work (order('position DESC')) but I'm not sure if that is by design or just coincidence, because there are no tests for that case.

daniel-rikowski avatar Feb 03 '17 18:02 daniel-rikowski

@daniel-rikowski I'll look into it.

openscript avatar Feb 04 '17 09:02 openscript