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

has_and_belongs_to_many error: Mongo::OperationFailure: invalid query

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

      I have the following association:

      class Account
        has_and_belongs_to_many :followed_by, class_name: Account.to_s
      end
      

      running the following:

      a = Account.new
      a.followed_by
      

      gives the error:

      Mongo::OperationFailure: invalid query
      	from /Users/fredrik/.rvm/gems/ruby-1.9.2-p180/gems/mongo-1.3.1/lib/mongo/cursor.rb:101:in `next_document'
      	from /Users/fredrik/.rvm/gems/ruby-1.9.2-p180/gems/mongo-1.3.1/lib/mongo/cursor.rb:248:in `each'
      	from /Users/fredrik/.rvm/gems/ruby-1.9.2-p180/gems/mongoid-2.3.3/lib/mongoid/cursor.rb:48:in `each'
      	from /Users/fredrik/.rvm/gems/ruby-1.9.2-p180/gems/mongoid-2.3.3/lib/mongoid/contexts/mongo.rb:212:in `iterate'
      	from /Users/fredrik/.rvm/gems/ruby-1.9.2-p180/gems/mongoid-2.3.3/lib/mongoid/criteria.rb:143:in `block in each'
      	from /Users/fredrik/.rvm/gems/ruby-1.9.2-p180/gems/mongoid-2.3.3/lib/mongoid/criteria.rb:143:in `tap'
      	from /Users/fredrik/.rvm/gems/ruby-1.9.2-p180/gems/mongoid-2.3.3/lib/mongoid/criteria.rb:143:in `each'
      	from /Users/fredrik/.rvm/gems/ruby-1.9.2-p180/gems/mongoid-2.3.3/lib/mongoid/relations/targets/enumerable.rb:153:in `each'
      	from /Users/fredrik/.rvm/gems/ruby-1.9.2-p180/gems/mongoid-2.3.3/lib/mongoid/relations/targets/enumerable.rb:223:in `entries'
      	from /Users/fredrik/.rvm/gems/ruby-1.9.2-p180/gems/mongoid-2.3.3/lib/mongoid/relations/targets/enumerable.rb:223:in `inspect'
      	from /Users/fredrik/.rvm/gems/ruby-1.9.2-p180/gems/mongoid-2.3.3/lib/mongoid/relations/referenced/many.rb:394:in `method_missing'
      	from /Users/fredrik/.rvm/gems/ruby-1.9.2-p180/gems/railties-3.1.3/lib/rails/commands/console.rb:45:in `start'
      	from /Users/fredrik/.rvm/gems/ruby-1.9.2-p180/gems/railties-3.1.3/lib/rails/commands/console.rb:8:in `start'
      	from /Users/fredrik/.rvm/gems/ruby-1.9.2-p180/gems/railties-3.1.3/lib/rails/commands.rb:40:in `<top (required)>'
      	from script/rails:11:in `require'
      	from script/rails:11:in `<main>'
      

      Also, doing a.followed_by << Account.first and then the following gives the same Mongo::OperationFailure: invalid query: a.followed_by

      doing a.reload works.

            Assignee:
            Unassigned Unassigned
            Reporter:
            fbjork Fredrik Björk
            Votes:
            0 Vote for this issue
            Watchers:
            0 Start watching this issue

              Created:
              Updated:
              Resolved: