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

Chaining scopes with "in" expression changes class' scopes

    • Type: Icon: Task Task
    • Resolution: Done
    • 2.3.0
    • Affects Version/s: None
    • Component/s: None
    • Labels:

      Let's consider the following class

      class Event
      include Mongoid::Document
      scope :best, where(:kind.in => ['party', 'concert'])
      scope :by_kind, lambda

      {|kind| :kind.in => [kind]}

      end

      When I run consoie, the following happens (look at the last result):

      > Event.best
      => #<Mongoid::Criteria
      selector: {:kind=>{"$in"=>["party", "concert"]}},
      ...
      > Event.best.by_kind('party')
      => #<Mongoid::Criteria
      selector: {:kind=>{"$in"=>["party"]}},
      ...
      > Event.best
      => #<Mongoid::Criteria
      selector: {:kind=>{"$in"=>["party"]}},
      ...

      It looks like the reason of this beahavior is in this line in 'where' method:
      https://github.com/mongoid/mongoid/blob/master/lib/mongoid/criterion/inclusion.rb#L164

      There should be no "!" mark at the end of "merge"

            Assignee:
            Unassigned Unassigned
            Reporter:
            netizer Krzysiek HerĂ³d
            Votes:
            0 Vote for this issue
            Watchers:
            0 Start watching this issue

              Created:
              Updated:
              Resolved: