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

.any_in.any_in should merge rather than destroy each other

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

      Scopes which use .also_in or .any_in should merge rather than destroy each other if you try and chain.

      currently it's suggested to use in().also_in as a chain, and then chain the first one to the second scope. But that provides the bad example of implying you want the first scope all the time with the second.

      >> User.collection_managers.count
      => 1
      >> User.staff.count
      => 11
      >> User.staff.collection_managers.count
      => 0
      >> User.collection_managers
      => #<Mongoid::Criteria
       selector: {:roles=>{"$in"=>["collection_manager"]}},
       options:  {},
       class:    User,
       embedded: false>
      
      >> User.staff
      => #<Mongoid::Criteria
       selector: {:roles=>{"$in"=>["super_admin", "product_admin", "customer_admin"]}},
       options:  {},
       class:    User,
       embedded: false>
      
      >> User.collection_managers.staff
      => #<Mongoid::Criteria
       selector: {:roles=>{"$in"=>[]}},
       options:  {},
       class:    User,
       embedded: false>
      

      these scopes should merge rather than destroy each other as they presently do.

      will attach specs when i have a free minute but wanted to assign this issue for anyone searching / and to remind me

            Assignee:
            Unassigned Unassigned
            Reporter:
            imajes James Cox
            Votes:
            0 Vote for this issue
            Watchers:
            0 Start watching this issue

              Created:
              Updated:
              Resolved: