Skip to content

Instantly share code, notes, and snippets.

@DouweM
Created October 28, 2012 00:09
Show Gist options
  • Save DouweM/3966970 to your computer and use it in GitHub Desktop.
Save DouweM/3966970 to your computer and use it in GitHub Desktop.
Proposed Mongoid::Relations::Proxy#eager_load_ids rewrite
def eager_load_ids(metadata, ids)
klass, foreign_key = metadata.klass, metadata.foreign_key
eager_loaded = klass.any_in(foreign_key => ids).entries
ids.each do |id|
IdentityMap.clear_many(klass, { foreign_key => id })
end
eager_loaded.each do |doc|
base_id = doc.__send__(foreign_key)
yield(doc, { foreign_key => base_id })
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment