Sha256: affb7f000329f15bfe23794e4a2717c07764a0d6076f2fc42c169ca5753c49fe

Contents?: true

Size: 544 Bytes

Versions: 3

Compression:

Stored size: 544 Bytes

Contents

# encoding: UTF-8
module MongoMapper
  module Plugins
    module Associations
      class BelongsToProxy < Proxy
        undef_method :object_id

        def replace(doc)
          if doc
            doc.save if doc.new?
            id = doc.id
          end

          owner[association.foreign_key] = id
          reset
        end

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

Version data entries

3 entries across 3 versions & 2 rubygems

Version Path
mongo_mapper_ign-0.7.7 lib/mongo_mapper/plugins/associations/belongs_to_proxy.rb
pwnash-mongo_mapper-0.7.6 lib/mongo_mapper/plugins/associations/belongs_to_proxy.rb
mongo_mapper_ign-0.7.6 lib/mongo_mapper/plugins/associations/belongs_to_proxy.rb