Sha256: 94ff40f57fc929f8441f6d118adaf456a218163d5bd77c784fc54442812ea6ea

Contents?: true

Size: 828 Bytes

Versions: 11

Compression:

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

11 entries across 11 versions & 4 rubygems

Version Path
mongo_mapper-0.6.6 lib/mongo_mapper/associations/belongs_to_polymorphic_proxy.rb
mongo_mapper-unstable-2009.12.4 lib/mongo_mapper/associations/belongs_to_polymorphic_proxy.rb
danielharan-mongo_mapper-0.6.5 lib/mongo_mapper/associations/belongs_to_polymorphic_proxy.rb
mongo_mapper-0.6.5 lib/mongo_mapper/associations/belongs_to_polymorphic_proxy.rb
webbynode-mongo_mapper-0.6.4 lib/mongo_mapper/associations/belongs_to_polymorphic_proxy.rb
mongo_mapper-0.6.4 lib/mongo_mapper/associations/belongs_to_polymorphic_proxy.rb
mongo_mapper-0.6.3 lib/mongo_mapper/associations/belongs_to_polymorphic_proxy.rb
mongo_mapper-0.6.2 lib/mongo_mapper/associations/belongs_to_polymorphic_proxy.rb
mongo_mapper-0.6.1 lib/mongo_mapper/associations/belongs_to_polymorphic_proxy.rb
mongo_mapper-unstable-2009.11.18 lib/mongo_mapper/associations/belongs_to_polymorphic_proxy.rb
mongo_mapper-0.6.0 lib/mongo_mapper/associations/belongs_to_polymorphic_proxy.rb