Sha256: 56a6068a76a57181501ba0f0208c64dc6b4df577624a70cc6d3ef3a382c511a0

Contents?: true

Size: 812 Bytes

Versions: 28

Compression:

Stored size: 812 Bytes

Contents

module MongoMapper
  module Plugins
    module Associations
      class BelongsToPolymorphicProxy < Proxy
        undef_method :object_id
        
        def replace(doc)
          if doc
            doc.save if doc.new?
            id, type = doc.id, doc.class.name
          end

          owner[association.foreign_key] = id
          owner[association.type_key_name] = type
          reset
        end

        protected
          def find_target
            return nil if association_class.nil? || owner[association.foreign_key].nil?
            association_class.find_by_id(owner[association.foreign_key])
          end

          def association_class
            proxy_owner[association.type_key_name] ? proxy_owner[association.type_key_name].constantize : nil
          end
      end
    end
  end
end

Version data entries

28 entries across 28 versions & 5 rubygems

Version Path
mongo_mapper-unstable-2010.2.18 lib/mongo_mapper/plugins/associations/belongs_to_polymorphic_proxy.rb
mongo_mapper-unstable-2010.2.17 lib/mongo_mapper/plugins/associations/belongs_to_polymorphic_proxy.rb
mongo_mapper-unstable-2010.2.16 lib/mongo_mapper/plugins/associations/belongs_to_polymorphic_proxy.rb
mongo_mapper-unstable-2010.2.15 lib/mongo_mapper/plugins/associations/belongs_to_polymorphic_proxy.rb
mongo_mapper-unstable-2010.2.12 lib/mongo_mapper/plugins/associations/belongs_to_polymorphic_proxy.rb
mongo_mapper-unstable-2010.2.11 lib/mongo_mapper/plugins/associations/belongs_to_polymorphic_proxy.rb
mongo_mapper-unstable-2010.2.10 lib/mongo_mapper/plugins/associations/belongs_to_polymorphic_proxy.rb
mongo_mapper-0.7.0 lib/mongo_mapper/plugins/associations/belongs_to_polymorphic_proxy.rb