Sha256: 26eec4d04d488f2b083109d90506812536afb008e44ccbe53b475c96a0598a73

Contents?: true

Size: 485 Bytes

Versions: 1

Compression:

Stored size: 485 Bytes

Contents

module MongoMapper
  module Associations
    class BelongsToProxy < Proxy
      def replace(doc)
        if doc
          doc.save if doc.new?
          id = doc.id
        end

        @owner.send("#{@association.belongs_to_key_name}=", id)
        reset
      end

      protected
        def find_target
          if association_id = @owner.send(@association.belongs_to_key_name)
            @association.klass.find_by_id(association_id)
          end
        end
    end
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
jnunemaker-mongomapper-0.3.3 lib/mongomapper/associations/belongs_to_proxy.rb