0

I'm trying to do a multi-column sort with the meta-search gem, but it's not working.

I'm doing it via some AJAX, so I'm calling Model.search() directly. I think I'm doing it right, but I'm not 100% sure because I can't seem to find a good doc on what the "meta_sort" parameter should be.

This is what I'm effectively calling, where my model is "Trade":

Trade.search("meta_sort"=>"exch.asc,fcondt.asc")

Should it be an array instead of a csv string?

I know that this works for a single-column sort, e.g.

Trade.search("meta_sort"=>"exch.asc")

Any help is appreciated.

Grant Birchmeier
  • 17,809
  • 11
  • 63
  • 98

1 Answers1

1

You can sort by many columns but single direction, "asc" direction is the default:

Syntax for fields of the same table:

{"meta_sort"=>"exch_and_fcondt.desc"}

Syntax for fields from different tables should be:

{"meta_sort"=>"table1_exch_and_table2_fcondt.desc"}

  • Do you know of any documentation for this syntax? – Grant Birchmeier Feb 26 '13 at 14:56
  • No, I don't. I just had problems doing complex ordering. I look at source code. The set_sort method in build.rb takes care of it. I my case I finally create a scope: scope(:sort_by_scope_name_desc) { order('my complex order') } The Model.search(meta_sort: 'scope_name_desc') executes the defined scope. – Ricard Forniol Agustí Mar 01 '13 at 12:05