RVRoadie wrote:
> 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 =
> 4)
> 
> #2 @i_rows = IRow.find_all_by_import_id(@import.id, :order
> => :row_sort)
>      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 => 
"row_sort")

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”
-- 
Posted via http://www.ruby-forum.com/.

-- 
You received this message because you are subscribed to the Google Groups "Ruby 
on Rails: Talk" group.
To post to this group, send email to [email protected].
To unsubscribe from this group, send email to 
[email protected].
For more options, visit this group at 
http://groups.google.com/group/rubyonrails-talk?hl=en.

Reply via email to