Sha256: 4131286316a409d0293a86fca52b2118cc3a0aa4918d20c28629a018b6925600
Contents?: true
Size: 1.12 KB
Versions: 6
Compression:
Stored size: 1.12 KB
Contents
module MongoMapper module Associations class ManyEmbeddedProxy < Proxy def replace(v) @_values = v.map { |e| e.kind_of?(EmbeddedDocument) ? e.attributes : e } reset end def build(attributes={}) doc = @association.klass.new(attributes) assign_root_document(doc) self << doc doc end def find(id) load_target @target.detect { |item| item.id == id } end def <<(*docs) if load_target docs.each do |doc| assign_root_document(doc) @target << doc end end end alias_method :push, :<< alias_method :concat, :<< private def find_target (@_values || []).map do |e| child = @association.klass.new(e) assign_root_document(child) child end end def root_document @owner._root_document || @owner end def assign_root_document(*docs) docs.each do |doc| doc._root_document = root_document end end end end end
Version data entries
6 entries across 6 versions & 2 rubygems