Sha256: 11abff4672b31cd8ad34a1a7f648423a59cf15cc132f897c883405c90eab4684

Contents?: true

Size: 473 Bytes

Versions: 2

Compression:

Stored size: 473 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)
        reload_target
      end

      protected
        def find_target
          if ref = @owner.send(@association.belongs_to_key_name)
            @association.klass.find(ref)
          end
        end
    end
  end
end

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
jnunemaker-mongomapper-0.3.0 lib/mongomapper/associations/belongs_to_proxy.rb
jnunemaker-mongomapper-0.3.1 lib/mongomapper/associations/belongs_to_proxy.rb