-
Type: Task
-
Resolution: Done
-
Affects Version/s: None
-
Component/s: None
-
Labels:None
I cannot seem to order my embedded documents.
Picture.where(:_id.in => @user.favorites.where(:favoritable_type => 'Picture').order_by(:created_at.desc).limit(8).map(&:favoritable_id))
I am trying to retrieve the last 8 favorited pictures. So I try to find all the favoritable_id}}s that have the {{favoritable_type set to Picture. Then try to order_by(:created_at.desc) I limit it to 8 limit(8).
The only thing here that does not work is the order_by(:created_at.desc), to be honest, I am not sure by what it is actually ordering now, as the more I add to a users "favorites" the more random the ordering becomes.
So what is the proper way to order an embedded document?
Thanks!