Last active
October 3, 2015 01:38
-
-
Save kfl62/2364764 to your computer and use it in GitHub Desktop.
HABTM relations return docs in the wrong order
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class Some | |
include Mongoid::Document | |
field :some_field | |
has_and_belongs_to_many :habtms | |
def sorted_habtms | |
hbtm_ids.each_with_object([]){|id,a| h = habtms.find(id); a << h} | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Superb, Thanks! I use it this way:
works great on small selections