Sha256: d3262eb6a09b3a71cd8a4957383e5e5cd7f15b68be726b7f49299e78606c3bca

Contents?: true

Size: 806 Bytes

Versions: 22

Compression:

Stored size: 806 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[reflection.foreign_key] = id
          owner[reflection.type_key_name] = type
          reset
        end

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

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

Version data entries

22 entries across 22 versions & 3 rubygems

Version Path
drogus-mongo_mapper-0.6.10 lib/mongo_mapper/plugins/associations/belongs_to_polymorphic_proxy.rb
mongo_mapper-unstable-2010.2.9 lib/mongo_mapper/plugins/associations/belongs_to_polymorphic_proxy.rb
mongo_mapper-unstable-2010.2.8 lib/mongo_mapper/plugins/associations/belongs_to_polymorphic_proxy.rb
mongo_mapper-unstable-2010.2.5 lib/mongo_mapper/plugins/associations/belongs_to_polymorphic_proxy.rb
mongo_mapper-unstable-2010.2.4 lib/mongo_mapper/plugins/associations/belongs_to_polymorphic_proxy.rb
novelys_mongo_mapper-0.6.12 lib/novelys_mongo_mapper/plugins/associations/belongs_to_polymorphic_proxy.rb
novelys_mongo_mapper-0.6.11 lib/novelys_mongo_mapper/plugins/associations/belongs_to_polymorphic_proxy.rb
mongo_mapper-unstable-2010.2.3 lib/mongo_mapper/plugins/associations/belongs_to_polymorphic_proxy.rb
novelys_mongo_mapper-0.6.10 lib/mongo_mapper/plugins/associations/belongs_to_polymorphic_proxy.rb
mongo_mapper-unstable-2010.2.2 lib/mongo_mapper/plugins/associations/belongs_to_polymorphic_proxy.rb
mongo_mapper-unstable-2010.2.1 lib/mongo_mapper/plugins/associations/belongs_to_polymorphic_proxy.rb
mongo_mapper-unstable-2010.1.31 lib/mongo_mapper/plugins/associations/belongs_to_polymorphic_proxy.rb
mongo_mapper-unstable-2010.1.30 lib/mongo_mapper/plugins/associations/belongs_to_polymorphic_proxy.rb
mongo_mapper-unstable-2010.1.29 lib/mongo_mapper/plugins/associations/belongs_to_polymorphic_proxy.rb
mongo_mapper-unstable-2010.1.28 lib/mongo_mapper/plugins/associations/belongs_to_polymorphic_proxy.rb
mongo_mapper-unstable-2010.1.27 lib/mongo_mapper/plugins/associations/belongs_to_polymorphic_proxy.rb
mongo_mapper-unstable-2010.1.26 lib/mongo_mapper/plugins/associations/belongs_to_polymorphic_proxy.rb
mongo_mapper-unstable-2010.1.25 lib/mongo_mapper/plugins/associations/belongs_to_polymorphic_proxy.rb
mongo_mapper-unstable-2010.1.22 lib/mongo_mapper/plugins/associations/belongs_to_polymorphic_proxy.rb
mongo_mapper-unstable-2010.1.21 lib/mongo_mapper/plugins/associations/belongs_to_polymorphic_proxy.rb