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

Eager loading fails if related object doesn't exist

    • Type: Icon: Bug Bug
    • Resolution: Done
    • Priority: Icon: Major - P3 Major - P3
    • 5.1.0
    • Affects Version/s: 4.0.0 final
    • Component/s: None
    • None

      I have a has_and_belongs_to_many relations, let's call it :somethings.

      There is a document in which :something_ids includes some ids that no longer exist in the related model (i.e. model.somethings.count is less than model.something_ids.count).

      If I try to eager load it with Model.includes(:somethings), then it fails with undefined method `id' for nil:NilClass here

      Might be fixed with a simple nil check on doc.

            Assignee:
            emily.stolfo Emily Stolfo
            Reporter:
            stanley90x Marek Stanczyk
            Votes:
            0 Vote for this issue
            Watchers:
            2 Start watching this issue

              Created:
              Updated:
              Resolved: