Sha256: fc3397e0bf14a2ca852ff37911c6370010507dd9a47885430d5d9805365403f6
Contents?: true
Size: 900 Bytes
Versions: 1
Compression:
Stored size: 900 Bytes
Contents
# encoding: UTF-8 module MongoMapper module Plugins module Associations class EmbeddedCollection < Collection def build(attributes={}) doc = klass.new(attributes) assign_references(doc) self << doc doc end def find(id) load_target target.detect { |item| item.id.to_s == id || item.id == id } end def count load_target target.size end def <<(*docs) load_target docs.each do |doc| assign_references(doc) target << doc end end alias_method :push, :<< alias_method :concat, :<< private def assign_references(*docs) docs.each { |doc| doc._parent_document = owner } end end end end end
Version data entries
1 entries across 1 versions & 1 rubygems
Version | Path |
---|---|
mongo_mapper_ign-0.7.8 | lib/mongo_mapper/plugins/associations/embedded_collection.rb |