Sha256: a04c319a81a1fe094704e5cf62e5a7dfb20156b66f94140fa68c5629fbebe599

Contents?: true

Size: 835 Bytes

Versions: 24

Compression:

Stored size: 835 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

24 entries across 24 versions & 6 rubygems

Version Path
crnixon-mongomapper-0.3.4 lib/mongomapper/associations/belongs_to_polymorphic_proxy.rb
djsun-mongomapper-0.3.3 lib/mongomapper/associations/belongs_to_polymorphic_proxy.rb
djsun-mongomapper-0.3.5.1 lib/mongomapper/associations/belongs_to_polymorphic_proxy.rb
djsun-mongomapper-0.3.5.2 lib/mongomapper/associations/belongs_to_polymorphic_proxy.rb
djsun-mongomapper-0.3.5.4 lib/mongomapper/associations/belongs_to_polymorphic_proxy.rb
djsun-mongomapper-0.3.5.5 lib/mongomapper/associations/belongs_to_polymorphic_proxy.rb
djsun-mongomapper-0.3.5 lib/mongomapper/associations/belongs_to_polymorphic_proxy.rb
hashrocket-mongomapper-0.3.10 lib/mongomapper/associations/belongs_to_polymorphic_proxy.rb
hashrocket-mongomapper-0.3.11 lib/mongomapper/associations/belongs_to_polymorphic_proxy.rb
hashrocket-mongomapper-0.3.12 lib/mongomapper/associations/belongs_to_polymorphic_proxy.rb
hashrocket-mongomapper-0.3.13 lib/mongomapper/associations/belongs_to_polymorphic_proxy.rb
hashrocket-mongomapper-0.3.14 lib/mongomapper/associations/belongs_to_polymorphic_proxy.rb
hashrocket-mongomapper-0.3.15 lib/mongomapper/associations/belongs_to_polymorphic_proxy.rb
hashrocket-mongomapper-0.3.3 lib/mongomapper/associations/belongs_to_polymorphic_proxy.rb
hashrocket-mongomapper-0.3.4.1 lib/mongomapper/associations/belongs_to_polymorphic_proxy.rb
hashrocket-mongomapper-0.3.4 lib/mongomapper/associations/belongs_to_polymorphic_proxy.rb
hashrocket-mongomapper-0.3.5 lib/mongomapper/associations/belongs_to_polymorphic_proxy.rb
hashrocket-mongomapper-0.3.6 lib/mongomapper/associations/belongs_to_polymorphic_proxy.rb
hashrocket-mongomapper-0.3.7 lib/mongomapper/associations/belongs_to_polymorphic_proxy.rb
hashrocket-mongomapper-0.3.8 lib/mongomapper/associations/belongs_to_polymorphic_proxy.rb