Skip to content

Instantly share code, notes, and snippets.

@nofxx
Created October 19, 2011 03:41
Show Gist options
  • Save nofxx/1297427 to your computer and use it in GitHub Desktop.
Save nofxx/1297427 to your computer and use it in GitHub Desktop.
Mongoid bug default_scope test
require 'mongoid'
Mongoid.configure do |config|
config.master = Mongo::Connection.new.db("foo_#{Time.now.to_i}")
end
class Project
include Mongoid::Document
field :name
field :state, :default => 'active'
# Comment 1 line and it works, both fails:
default_scope where(:state => 'active')
scope :inactive, any_in(:state => [:done, :wip])
end
@nofxx
Copy link
Author

nofxx commented Oct 19, 2011

NoMethodError: undefined method `has_key?' for "active":String
    from /usr/lib/ruby/gems/1.9.1/gems/mongoid-2.3.2/lib/mongoid/criteria.rb:402:in `block (2 levels) in update_selector'
    from /usr/lib/ruby/gems/1.9.1/gems/mongoid-2.3.2/lib/mongoid/criteria.rb:398:in `each_pair'
    from /usr/lib/ruby/gems/1.9.1/gems/mongoid-2.3.2/lib/mongoid/criteria.rb:398:in `block in update_selector'
    from /usr/lib/ruby/gems/1.9.1/gems/mongoid-2.3.2/lib/mongoid/criteria.rb:396:in `tap'
    from /usr/lib/ruby/gems/1.9.1/gems/mongoid-2.3.2/lib/mongoid/criteria.rb:396:in `update_selector'
    from /usr/lib/ruby/gems/1.9.1/gems/mongoid-2.3.2/lib/mongoid/criterion/inclusion.rb:184:in `in'
    from /usr/lib/ruby/gems/1.9.1/gems/mongoid-2.3.2/lib/mongoid/finders.rb:15:in `any_in'

scope + default_scope issue?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment