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

Limit and offset scope options on embedded objects are breaking on empty result

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

      Hi!

      We found a problem with the mongoid gem. Limit and offset options for scopes on embedded objects are breaking if the result would be empty. See the following piece of code:

      https://gist.github.com/3891253

      Calling Something.test leads to the following output:

      test pagination with page 1 and limit 6
      ["test object 0", "test object 1", "test object 2", "test object 3", "test object 4", "test object 5"]
      test pagination with page 2 and limit 6
      ["test object 6", "test object 7", "test object 8", "test object 9"]
      test pagination with page 3 and limit 6
      []
      test embedded pagination with page 1 and limit 6
      ["embedded 0-0", "embedded 0-1", "embedded 0-2", "embedded 0-3", "embedded 0-4", "embedded 0-5"]
      test embedded pagination with page 2 and limit 6
      ["embedded 0-6", "embedded 0-7", "embedded 0-8", "embedded 0-9"]
      test embedded pagination with page 3 and limit 6
      NoMethodError - undefined method `each' for nil:NilClass:
              /<path_to_gems>/gems/mongoid-3.0.6/lib/mongoid/contextual/memory.rb:120:in `each'
      ....
      

            Assignee:
            durran Durran Jordan
            Reporter:
            TheWudu TheWudu [X]
            Votes:
            0 Vote for this issue
            Watchers:
            0 Start watching this issue

              Created:
              Updated:
              Resolved: