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

Chained "in" when querying on ids should evolve to ObjectId before the value comparison

    • Type: Icon: Bug Bug
    • Resolution: Fixed
    • Priority: Icon: Minor - P4 Minor - P4
    • 7.0.0, 6.4.0
    • Affects Version/s: 5.2.1
    • Component/s: None
    • None
    • Environment:
      Origin v2.3.1

      I have a simple class:

      class Article
        include Mongoid::Document
      end
      

      Given this query:

      Article.in(id: ['55794bd9416472d4e8050000'])
      => #<Mongoid::Criteria
        selector: {"_id"=>{"$in"=>[BSON::ObjectId('55794bd9416472d4e8050000')]}}
        options:  {}
        class:    Article
        embedded: false>
      

      If I double the in, I don't have the selector anymore:

      Article.in(id: ['55794bd9416472d4e8050000']).in(id: ['55794bd9416472d4e8050000'])
      => #<Mongoid::Criteria
        selector: {"_id"=>{"$in"=>[]}}
        options:  {}
        class:    Article
        embedded: false>
      

      Whereas if I pass an ObjectId to the second in, the selector is correct:

      Article.in(id: ['55794bd9416472d4e8050000']).in(id: [BSON::ObjectId('55794bd9416472d4e8050000')])
      => #<Mongoid::Criteria
        selector: {"_id"=>{"$in"=>[BSON::ObjectId('55794bd9416472d4e8050000')]}}
        options:  {}
        class:    Article
        embedded: false>
      

      This should work with both syntax. I've dug a little and found that the ObjectId evolve occurs after the merge of the in values (old_val & new_val).

            Assignee:
            emily.stolfo Emily Stolfo
            Reporter:
            CedricBm Cedric Beaumont
            Votes:
            1 Vote for this issue
            Watchers:
            3 Start watching this issue

              Created:
              Updated:
              Resolved: