Rails/ActiveRecord: Return order with ActiveRecord#find(Array) -


I am using Ruby on Rails / ActiveRecord and I'm having trouble with an ActiveRecord # find call. I am storing in the database A serial array ID of recently viewed document ID is stored in descending order in order of last seen, so the most recently viewed document id is in the first array. The array contains up to 10 IDs.

So far, the problem is that ActiveRecord # find (Array) is ignoring the order in which ideas appear in the array. So if I type Document.find ([1, 2, 3]), then I get the same result as if I document. Remove ([3, 2, 1]).

My question, then, is this: How can I get an ActiveRecord result array which has sent the ID to #Fund? Or, if ActiveRecord does not do this directly, how can I sort out Array as a result after this fact?

Thank you very much for the contribution of people!

ActiveRecord is an interface for your database and in the same order you have the archive that gives them the database If you do not supply the 'order' parameter, the returned order (effectively) is random.

If your order is ascending or descending:

  results = SomeModelName.find ([1,2,3], order = & gt; "id") # Ascending order result = some modellname.find ([1,2,3], order = & gt; "id desc") # descending if the ID order is not ascending or descending  
  id = [1, 3, 2] r = Some ModelName.find (ID) results = ids.map {| ID | R.detect {| Each. Every.id == id}}  

Comments

Popular posts from this blog

oracle - The fastest way to check if some records in a database table? -

php - multilevel menu with multilevel array -

jQuery UI: Datepicker month format -