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

strange behavior with scope/exists

      Pseudo Setup:

      def AModel
       has_many :test_models
      end
      
      def TestModel
       belongs_to a_model
        scope :test_scope, where(:test_field.exists => false)
      end
      

      Then when I call:

      AModel.first.test_models.test_scope 
      

      I get:

      #<Mongoid::Criteria
        selector: {"a_model_id"=>"1", "test_field"=>nil}
        options:  {}
        class:    TestModel
        embedded: false>
      

      but the written out query is different (and correct)

      AModel.first.test_models.where(:test_field.exists => false)
      

      returns

      #<Mongoid::Criteria
        selector: {"a_model_id"=>"1", "test_field"=>{"$exists"=>false}}
        options:  {}
        class:    TestModel
        embedded: false>
      

      This only appears to be a problem when calling on a 'related' object.

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

              Created:
              Updated:
              Resolved: