Sha256: 52e2d9d63875938cbdbb78687c6c8346620298f03ee0a04866fc1f518b02fb0d
Contents?: true
Size: 767 Bytes
Versions: 10
Compression:
Stored size: 767 Bytes
Contents
module MongoMapper module Plugins module Associations class BelongsToPolymorphicProxy < Proxy def replace(doc) if doc doc.save if doc.new? id, type = doc.id, doc.class.name end owner[reflection.foreign_key] = id owner[reflection.type_key_name] = type reset end protected def find_target return nil if association_class.nil? || owner[reflection.foreign_key].nil? association_class.first(:id => owner[reflection.foreign_key]) end def association_class proxy_owner[reflection.type_key_name] ? proxy_owner[reflection.type_key_name].constantize : nil end end end end end
Version data entries
10 entries across 10 versions & 2 rubygems