Import has_many IRows
IRow belongs to Import
@import = Import.find(params[:id])
Shouldn't both of the following statements work the same?
#1 :@i_rows = @import.i_rows(:order => :row_sort)
Generates: SELECT * FROM "i_rows" WHERE ("i_rows".import_id =
#2 @i_rows = IRow.find_all_by_import_id(@import.id, :order
Generates: SELECT * FROM "i_rows" WHERE ("i_rows"."import_id" =
4) ORDER BY row_sort
What is wrong with #1. It returns same data as #2, but just not
sorted. No syntax or SQL errors are generated by #1.
The :order is an option passed to the "find" method of an ActiveRecord
instance, but @import.i_rows (assuming this is a to_many association) is
a reference to an Array of ActiveRecord instances so #1 makes no sense.
I think you might want @i_rows = @import.i_rows.find(:all, :order =>
Besides that you're syntax for setting :order is rather non-idomatic
Rails. Did you look at the documentation for usage of :order? Using the
symbol will work, but symbols should be used to identify things not
represent SQL fragments. The text of the symbol in your case is
important as a string of characters rather than the name of some
"thing." Use a string for those cases.
Excerpt from Rails docs:
:order - An SQL fragment like “created_at DESC, name”