I am using mySQL. I run two different finds and once I get them both
back I want to merge the results and order them? What is the best way
to go about this?
Thanks for your help!
–
John K.
[email protected]
I am using mySQL. I run two different finds and once I get them both
back I want to merge the results and order them? What is the best way
to go about this?
Thanks for your help!
–
John K.
[email protected]
Assuming that you’re not mixing results of two different classes (apples
and oranges)…
@all_apples = @first_apples + @second_apples
@sorted_apples = @all_apples.sort { |a,b| a.sortable_value <=>
b.sortable_value }
But, I would strongly recommend investigating the possibility of doing
it all in one sql call. You’ll find it much faster, especially if
you’re dealing with a ton of apples. find_by_sql may be your only
option in that regard, but it might be worth it. If you’re only dealing
with a bushel of apples each time, then the above may be sufficient.
This forum is not affiliated to the Ruby language, Ruby on Rails framework, nor any Ruby applications discussed here.
Sponsor our Newsletter | Privacy Policy | Terms of Service | Remote Ruby Jobs