Sha256: e045fccf5e7ae594dce7419b626e37f7bcd7b5e67af206a640a53e4bf3af5a48
Contents?: true
Size: 926 Bytes
Versions: 15
Compression:
Stored size: 926 Bytes
Contents
# encoding: UTF-8 module MongoMapper module Plugins module Associations class BelongsToPolymorphicProxy < Proxy def replace(doc) if doc doc.save unless doc.persisted? id, type = doc.id, doc.class.name end proxy_owner[association.foreign_key] = id proxy_owner[association.type_key_name] = type reset unless doc.nil? loaded @target = doc end @target end protected def find_target return nil if association_class.nil? || proxy_owner[association.foreign_key].nil? association_class.find_by_id(proxy_owner[association.foreign_key]) end def association_class proxy_owner[association.type_key_name] ? proxy_owner[association.type_key_name].constantize : nil end end end end end
Version data entries
15 entries across 15 versions & 3 rubygems