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

eager loading with default scopes

    XMLWordPrintable

    Details

    • Type: Task
    • Status: Closed
    • Priority: Major - P3
    • Resolution: Gone away
    • Affects Version/s: None
    • Fix Version/s: 5.0.1
    • Component/s: None
    • Labels:

      Description

      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.

        Attachments

          Activity

            People

            Assignee:
            dianna.hohensee Dianna Hohensee
            Reporter:
            doughsay doughsay
            Votes:
            0 Vote for this issue
            Watchers:
            1 Start watching this issue

              Dates

              Created:
              Updated:
              Resolved: