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

has many with order has been reseted when using only

    • Type: Icon: Task Task
    • Resolution: Done
    • 3.0.6
    • Affects Version/s: None
    • Component/s: None
    • Labels:

      I have a course with many lesson. Here is my models:

      class Course
      include Mongoid::Document
      has_many :lessons, order:

      {position: 1}

      end

      class Lesson
      belongs_to :course
      end

      The has many relation is ordered with the position field. Everything work fine when I run the follow command:

      >> Course.find("503a4d36c32266bdd48f5593").lessons.collect{|l| "#

      {l.position}. #{l.name}"}
      => ["1. Session 3", "2. Session 4", "3. Session 1", "4. Session 2"]

      But now the same command with the "only" selector will erase my ordering:

      >> Course.find("503a4d36c32266bdd48f5593").lessons.only(:name, :position).collect{|l| "#{l.position}

      . #

      {l.name}

      "}
      => ["3. Session 1", "4. Session 2", "1. Session 3", "2. Session 4"]

      I missed something ?

            Assignee:
            durran Durran Jordan
            Reporter:
            skyporter skyporter
            Votes:
            0 Vote for this issue
            Watchers:
            0 Start watching this issue

              Created:
              Updated:
              Resolved: