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

Mongoid replaces empty string with nil in finders.

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

      class Model
        include Mongoid::Document
        include Mongoid::Timestamps
        
        field :foreign_identity
        index :foreign_identity, :unique => true
        validates :foreign_identity, :uniqueness => true
      end
      
      Model.create! :foreign_identity => ''
      Model.create! :foreign_identity => '' #uniqueness validation failed
      Model.count #reports "2"
      
      Model.where(:foreign_identity => '').first #returns "nil"
      

      This happens because while creating foreign_identity is given value "", however where method queries for value nil for foreign_identity and so doesn't find any. Same with validation.
      P.S. It seem to only happen if attribute name is foreign_identity.

            Assignee:
            Unassigned Unassigned
            Reporter:
            nasa42 nasa42
            Votes:
            0 Vote for this issue
            Watchers:
            0 Start watching this issue

              Created:
              Updated:
              Resolved: