Sha256: 9db7e4aae635c5cd4d9b2b9b8c2a67563952c140f6cceb3ad1c13ba37a0287b1
Contents?: true
Size: 851 Bytes
Versions: 1
Compression:
Stored size: 851 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.belongs_to_key_name}=", 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.belongs_to_key_name) 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 |
---|---|
jnunemaker-mongomapper-0.3.3 | lib/mongomapper/associations/belongs_to_polymorphic_proxy.rb |