Sha256: 4ab36db67de7a51f020bde5dbb0a34129ca506335d4844e1f7b8b085192d117c

Contents?: true

Size: 487 Bytes

Versions: 3

Compression:

Stored size: 487 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(association_id)
          end
        end
    end
  end
end

Version data entries

3 entries across 3 versions & 2 rubygems

Version Path
djsun-mongomapper-0.3.1.1 lib/mongomapper/associations/belongs_to_proxy.rb
djsun-mongomapper-0.3.1 lib/mongomapper/associations/belongs_to_proxy.rb
jnunemaker-mongomapper-0.3.2 lib/mongomapper/associations/belongs_to_proxy.rb