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

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

    XMLWordPrintable

    Details

    • Type: Task
    • Status: Closed
    • Resolution: Done
    • Affects Version/s: None
    • Fix Version/s: 4.0.0 final
    • Component/s: None
    • Labels:

      Description

      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

        Attachments

          Activity

            People

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

              Dates

              Created:
              Updated:
              Resolved: