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

Putting any other scope preceding any_of throws an error

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

      For instance, I have the following class:
      class Project
      include Mongoid::Document MONGOID-5.0.0.rc.8
      field :title
      field :body
      field :author

      scope :who, lambda { | name| {:where => {:author => /\bname\b/i} }
      scope :search, lambda { | query | {:any_of => [ { :title => /\b#

      {query}\b/i }, { :body => /\b#{query}

      \b/i } ] } }
      end

      OK queries

      Project.who('joe').count #=> integer
      Project.search('Hi').count #=> integer
      Project.search('Hi').who('joe').count #=> integer

      Bad queries

      Project.who('joe').search('Hi').count

      => ERROR in log:

      BSON::InvalidObjectId: illegal ObjectId format
      from C:/Ruby192/lib/ruby/gems/1.9.1/gems/bson-1.2.4/lib/bson/types/object_id.rb:122:in `from_string'
      from C:/Ruby192/lib/ruby/gems/1.9.1/gems/mongoid-2.0.0.rc.8/lib/mongoid/extensions/object_id/conversions.rb:69:in `convert
      '
      from C:/Ruby192/lib/ruby/gems/1.9.1/gems/mongoid-2.0.0.rc.8/lib/mongoid/criterion/optional.rb:114:in `block in for_ids'

      Any idea why this is? By the way, this is fine in 2.0.0.rc.7

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

              Created:
              Updated:
              Resolved: