Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Get all from table AND sort?

Using the following code in my controller, I am able to retrieve all rows from my table, but it won't sort by the column last_name. Any suggestions?

 @pi_names = PiName.all(:order => 'pi_names.last_name DESC')
like image 375
Jonah Katz Avatar asked Aug 09 '11 17:08

Jonah Katz


2 Answers

Try

 @pi_names = PiName.order('pi_names.last_name DESC').all
like image 193
Dogbert Avatar answered Nov 06 '22 07:11

Dogbert


Alternative syntax allowing any errors to potentially be caught prior to runtime:

@pi_names = PiName.order(last_name: :desc)
like image 38
Jon Schneider Avatar answered Nov 06 '22 09:11

Jon Schneider