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

any_of does not localize multiple fields

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

      any_of doesn't suffix the field key with the locale if more than one condition is provided.

      1. Working fine:
        Post.any_of title: 'Hello World' # => { :title.en => 'Hello World' }
      1. Working not so fine:
        Post.any_of title: 'Hello World', description: 'Hello World' # => { :title => 'Hello World', :description => 'Hello World' }

      I looked around a little, and it seems to be caused by the []= method in the Selector module because it doesn't recognize these kinds of nested keys. I changed

      Unable to find source-code formatter for language: handle_and_or_value. Available languages are: actionscript, ada, applescript, bash, c, c#, c++, cpp, css, erlang, go, groovy, haskell, html, java, javascript, js, json, lua, none, nyan, objc, perl, php, python, r, rainbow, ruby, scala, sh, sql, swift, visualbasic, xml, yaml
      (values)

      to localize keys and now things work great.

      def handle_and_or_value(values)
      [].tap do |result|
      result.push(*values.map do |value|
      Hash[value.map{ |key, value| key = "#

      {key}

      .#{::I18n.locale}" if klass.fields[key.to_s].try(:localized?); [key, try_to_typecast(key, value)] }]
      end)
      end
      end

      I'm using Mongoid 2.4.3, and I'm loving it! Keep up the good work

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

              Created:
              Updated:
              Resolved: