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

Any_of and matches

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

      I have just upgraded Mongoid from 2 to 3 but I think I've got a bug.

      The issue comes from this scope :

      scope :untranslated, ->(locales){ any_of(locales.to_a.inject([]) { |q, locale| q += [{ 'locales.code'.to_sym.ne => locale }, { :locales.matches => { :code => locale, :state => false }}] }) }
      
      irb(main):003:0> Translation.untranslated('fr').count
      NoMethodError: undefined method `specify' for #<SymbolOperator:0x000000049d4b18>
      

      It's a bit cryptic, but if I split the queries

      irb(main):005:0> Translation.where('locales.code'.to_sym.ne => 'fr').count
      => 0
      irb(main):006:0> Translation.where(:locales.matches => { :code => 'fr', :state => false }).count
      => 0
      irb(main):007:0> Translation.any_of([{ 'locales.code'.to_sym.ne => 'fr' }, { :locales.matches => { :code => 'fr', :state => false }}]).count
      NoMethodError: undefined method `specify' for #<SymbolOperator:0x00000004a557e0>
              from /home/kochka/.gem/ruby/1.9.1/gems/origin-1.0.3/lib/origin/mergeable.rb:134:in `block (3 levels) in __multi__'
              from /home/kochka/.gem/ruby/1.9.1/gems/origin-1.0.3/lib/origin/mergeable.rb:133:in `each'
              from /home/kochka/.gem/ruby/1.9.1/gems/origin-1.0.3/lib/origin/mergeable.rb:133:in `inject'
              from /home/kochka/.gem/ruby/1.9.1/gems/origin-1.0.3/lib/origin/mergeable.rb:133:in `block (2 levels) in __multi__'
              from /home/kochka/.gem/ruby/1.9.1/gems/origin-1.0.3/lib/origin/mergeable.rb:130:in `each'
              from /home/kochka/.gem/ruby/1.9.1/gems/origin-1.0.3/lib/origin/mergeable.rb:130:in `block in __multi__'
              from /home/kochka/.gem/ruby/1.9.1/gems/origin-1.0.3/lib/origin/mergeable.rb:128:in `tap'
              from /home/kochka/.gem/ruby/1.9.1/gems/origin-1.0.3/lib/origin/mergeable.rb:128:in `__multi__'
              from /home/kochka/.gem/ruby/1.9.1/gems/origin-1.0.3/lib/origin/selectable.rb:373:in `or'
              from (eval):1:in `any_of'
              from (irb):7
              from /home/kochka/.gem/ruby/1.9.1/gems/railties-3.2.6/lib/rails/commands/console.rb:47:in `start'
              from /home/kochka/.gem/ruby/1.9.1/gems/railties-3.2.6/lib/rails/commands/console.rb:8:in `start'
              from /home/kochka/.gem/ruby/1.9.1/gems/railties-3.2.6/lib/rails/commands.rb:41:in `<top (required)>'
              from script/rails:6:in `require'
              from script/rails:6:in `<main>'
      

      => Ruby 1.9.3, Rails 3.2.6, Mongoid last commit from github

      Any ideas ?

      Thanks !

            Assignee:
            Unassigned Unassigned
            Reporter:
            kochka Sébastien
            Votes:
            0 Vote for this issue
            Watchers:
            0 Start watching this issue

              Created:
              Updated:
              Resolved: