jnunemaker/mongomapper — Issue #386: find_each doesn't call the block when used at the end of a criteria chain
Author: brianhempel
Created: 2012-02-09 18:52:34+00:00
State: open

Discovered while answering [Specify fields to be returned with find_each?](http://stackoverflow.com/questions/9203276/specify-fields-to-be-returned-with-find-each#answer-9216645) on StackOverflow:

User.find_each { |user| p user } # block called
User.fields(:id).find_each { |user| p user } # block not called

This seems odd. How can this be fixed? Redecorate the query? I'm assuming there's a reason why plucky returns an enumerator rather than calling the block...? Can plucky run a block if given...return enumerator otherwise?

Code:

https://github.com/jnunemaker/plucky/blob/master/lib/plucky/query.rb#L54
https://github.com/jnunemaker/mongomapper/blob/master/lib/mongo_mapper/plugins/querying.rb#L13