Uploaded image for project: 'Mongoid'
  1. Mongoid
  2. MONGOID-200

order_by() on embedded documents?

    • Type: Icon: Task Task
    • Resolution: Done
    • 12_01_17
    • 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!

            Assignee:
            Unassigned Unassigned
            Reporter:
            meskyanichi Michael van Rooijen
            Votes:
            0 Vote for this issue
            Watchers:
            0 Start watching this issue

              Created:
              Updated:
              Resolved: