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

Matchers/Matchable::Ne: wrong semantics for array attributes

    • Type: Icon: Task Task
    • Resolution: Done
    • 4.0.0 final
    • Affects Version/s: None
    • Component/s: None

      The matcher/matchable corresponds to the Mongo $ne operator which treats array-valued attributes in a special way: It selects documents whose attribute does not contain the specified value.

      Say, we have a collection of documents like this:

      [

      { id: 1, state: ['locked'] }

      ,

      { id: 2, state: [] }

      ]

      Now,

      Doc.where(state: 'locked')

      matches only the first document and the Default matcher/matchable mirrors this behavior.

      However,

      Doc.ne(state: 'locked')

      matches only the second document, whereas the Ne matcher/matchable matches both.

      I suggest that Ne::matches? be implemented like this:

      def matches?(value)
      #@attribute != value.values.first
      !super(value.values.first)
      end

            Assignee:
            durran Durran Jordan
            Reporter:
            mschuerig mschuerig
            Votes:
            0 Vote for this issue
            Watchers:
            0 Start watching this issue

              Created:
              Updated:
              Resolved: