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

Includes throws NoMethodError when document is nil

    • Type: Icon: Bug Bug
    • Resolution: Done
    • Priority: Icon: Major - P3 Major - P3
    • 6.0.0, 5.1.5
    • Affects Version/s: 5.1.4
    • Component/s: None
    • None

      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

            Assignee:
            emily.stolfo Emily Stolfo
            Reporter:
            ebcarlson Eric Carlson
            Votes:
            0 Vote for this issue
            Watchers:
            1 Start watching this issue

              Created:
              Updated:
              Resolved: