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

Includes throws NoMethodError when document is nil

    XMLWordPrintable

    Details

    • Type: Bug
    • Status: Closed
    • Priority: Major - P3
    • Resolution: Fixed
    • Affects Version/s: 5.1.4
    • Fix Version/s: 6.0.0, 5.1.5
    • Component/s: None
    • Labels:
      None
    • Sprint:
      Ruby Sprint 42

      Description

      When using .includes on a belongs_to relation that has nil values the following exception is thrown:

      Failure/Error: doc.set_relation(@metadata.name, element)

      NoMethodError:
      undefined method `set_relation' for nil:NilClass
      Did you mean? set_trace_func

      Checking for nil doc in Mongoid::Eager::Relations seems to resolve the issue:

      def set_relation(doc, element)
      doc.set_relation(@metadata.name, element) unless doc.blank?
      end

        Attachments

          Issue Links

            Activity

              People

              Assignee:
              emily.stolfo Emily Stolfo
              Reporter:
              ebcarlson63 Eric Carlson
              Participants:
              Votes:
              0 Vote for this issue
              Watchers:
              2 Start watching this issue

                Dates

                Created:
                Updated:
                Resolved: