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

eager loading with default scopes

    • Type: Icon: Task Task
    • Resolution: Done
    • Priority: Icon: Major - P3 Major - P3
    • 5.0.1
    • Affects Version/s: None
    • Component/s: None

      I'm seeing this behavior in mongoid 3 when using eager loading with default scopes. I'm not sure if it's a bug or by design.

      Simple example:

      class Person
        include Mongoid::Document
        field :name
        has_many :hobbies
      end
      
      class Hobby
        include Mongoid::Document
        field :name
        field :status
        belongs_to :person
        default_scope where(:status.ne => 'deleted')
      end
      

      After creating a person and two hobbies, one of them with status = 'deleted', person = Person.includes(:hobbies).first correctly performs the eager load query (including the default scope), but then person.hobbies hits the database again. Removing the default scope causes it to work as expected.

            Assignee:
            dianna.hohensee@mongodb.com Dianna Hohensee (Inactive)
            Reporter:
            doughsay doughsay
            Votes:
            0 Vote for this issue
            Watchers:
            1 Start watching this issue

              Created:
              Updated:
              Resolved: