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

Add test for dotted attribute assignment in default scope

    • Type: Icon: Improvement Improvement
    • Resolution: Fixed
    • Priority: Icon: Unknown Unknown
    • 8.1.0
    • Affects Version/s: None
    • Component/s: Query
    • None

      The default scope docs have this bit:

      Because a default scope initializes fields in new models as just described,
      defining a default scope with a dotted key and a simple literal value is
      not possible:
      
      .. code-block:: ruby
      
        class Band
          include Mongoid::Document
          field :name, type: String
          field :tags, type: Hash
      
          default_scope ->{ where('tags.foo' => 'bar') }
        end
      
        Band.create! # exception: BSON::String::IllegalKey ('tags.foo' is an illegal key in MongoDB. Keys may not start with '$' or contain a '.'.)
      
      

      This behavior will change when driver accepts dots in field names, which will be a breaking change for Mongoid. There should be a test added to document the present behavior and documentation updated when the driver behavior changes.

            Assignee:
            neil.shweky@mongodb.com Neil Shweky (Inactive)
            Reporter:
            oleg.pudeyev@mongodb.com Oleg Pudeyev (Inactive)
            Votes:
            0 Vote for this issue
            Watchers:
            1 Start watching this issue

              Created:
              Updated:
              Resolved: