mongoid/mongoid — pull request #2765 by arthurnn (2013-01-31 04:52:49+00:00)
Title: Enumerable.matching_document _unloaded double query fix

After debugging #2761, I realize that has_and_belongs_to_many were querying the DB twice with the same selector.

When there was a many to many, and the target was not loaded and target.first was called, _unloaded was calling the db twice in order to load.