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

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

    XMLWordPrintable

    Details

    • Type: Task
    • Status: Closed
    • Resolution: Done
    • Affects Version/s: None
    • Fix Version/s: 4.0.0 final
    • Component/s: None
    • Labels:

      Description

      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>
      
      

        Attachments

          Activity

            People

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

              Dates

              Created:
              Updated:
              Resolved: