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

Sorting by localized fields still a little wonky when using default scopes

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

      Refers to MONGOID-2598
      Mongoid 3.1.4

      class Whatever
        include Mongoid::Document
        field :name, localize: true
        default_scope asc(:name)
      end
      
      [2] pry(main)> I18n.locale = "en"
      => "en"
      
      [3] pry(main)> Whatever.all
      => #<Mongoid::Criteria
        selector: {}
        options:  {:sort=>{"name.en"=>1}}
        class:    Whatever
        embedded: false>
      
      [4] pry(main)> I18n.locale = "es"
      => "es"
      
      # Note the locale in the scope didn't change here...
      [5] pry(main)> Whatever.all
      => #<Mongoid::Criteria
        selector: {}
        options:  {:sort=>{"name.en"=>1}}
        class:    Whatever
        embedded: false>
      
      # This works as expected
      [6] pry(main)> Whatever.unscoped.asc(:name)
      => #<Mongoid::Criteria
        selector: {}
        options:  {:sort=>{"name.es"=>1}}
        class:    Whatever
        embedded: false>
      
      

            Assignee:
            durran Durran Jordan
            Reporter:
            astjohn Adam St. John
            Votes:
            0 Vote for this issue
            Watchers:
            0 Start watching this issue

              Created:
              Updated:
              Resolved: