Sha256: b5c71168972348c30c16f56975e177f7575effddef8347fd960af75efe1e38a1
Contents?: true
Size: 861 Bytes
Versions: 1
Compression:
Stored size: 861 Bytes
Contents
module MongoMapper module Associations class BelongsToPolymorphicProxy < Proxy def replace(doc) if doc doc.save if doc.new? id, type = doc.id, doc.class.name end @owner.send("#{@association.foreign_key}=", id) @owner.send("#{@association.type_key_name}=", type) reset end protected def find_target if proxy_id && proxy_class proxy_class.find_by_id(proxy_id) end end def proxy_id @proxy_id ||= @owner.send(@association.foreign_key) end def proxy_class @proxy_class ||= begin klass = @owner.send(@association.type_key_name) klass && klass.constantize end end end end end
Version data entries
1 entries across 1 versions & 1 rubygems
Version | Path |
---|---|
djsun-mongomapper-0.4.1.2 | lib/mongomapper/associations/belongs_to_polymorphic_proxy.rb |