-
Type: Task
-
Resolution: Done
-
Affects Version/s: None
-
Component/s: None
I have a course with many lesson. Here is my models:
class Course
include Mongoid::Document
has_many :lessons, order:
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 ?