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

Criteria#find behaviour

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

      ids = ["50d0e368ebd9df5e7c000001", "50d0e368ebd9df5e7c000002"]
      User.find(*ids).each {|u| puts u}
      # [#<User _id: 50d0e368ebd9df5e7c000001>, #<User _id: 50d0e368ebd9df5e7c000002>]
      

      This works like charm, but what if ...

      ids.pop
      User.find(*ids).each {|u| puts u}
      NoMethodError: undefined method `each' for #<User:0x0000000610d488>
      	from /var/lib/gems/1.9.1/gems/mongoid-3.0.14/lib/mongoid/attributes.rb:225:in `method_missing'
      	from (irb):58
      	from /var/lib/gems/1.9.1/gems/railties-3.2.9/lib/rails/commands/console.rb:47:in `start'
      	from /var/lib/gems/1.9.1/gems/railties-3.2.9/lib/rails/commands/console.rb:8:in `start'
      	from /var/lib/gems/1.9.1/gems/railties-3.2.9/lib/rails/commands.rb:41:in `<top (required)>'
      	from script/rails:6:in `require'
      	from script/rails:6:in `<main>'
      

      I think this behavior introduces many bugs, especially if ids list is coming from request.
      I suggest that find should always return list. May be introduce a Criteria#get for one id case.
      Thanks.

            Assignee:
            Unassigned Unassigned
            Reporter:
            tabdulradi Tamer Mohammed AbdulRadi
            Votes:
            0 Vote for this issue
            Watchers:
            0 Start watching this issue

              Created:
              Updated:
              Resolved: