Sha256: 3e091da596f6014ce1c2a2a8576ae7bdd5096fa7d825ede5ccb265b2e53730d0
Contents?: true
Size: 961 Bytes
Versions: 22
Compression:
Stored size: 961 Bytes
Contents
# encoding: utf-8 module Mongoid module Relations module Eager class HasAndBelongsToMany < Base def preload @docs.each do |d| set_relation(d, []) end entries = {} each_loaded_document do |doc| entries[doc.send(key)] = doc end @docs.each do |d| keys = d.send(group_by_key) docs = entries.values_at(*keys).compact set_relation(d, docs) end end def keys_from_docs keys = Set.new @docs.each do |d| keys += d.send(group_by_key) end keys.to_a end def set_relation(doc, element) doc.__build__(@metadata.name, element, @metadata) unless doc.blank? end def group_by_key @metadata.foreign_key end def key @metadata.primary_key end end end end end
Version data entries
22 entries across 20 versions & 2 rubygems