Sha256: fabe640920704f535dd378aacfd45d00acd580126b341a2660af5c528728d940

Contents?: true

Size: 485 Bytes

Versions: 16

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.foreign_key}=", id)
        reset
      end

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

Version data entries

16 entries across 16 versions & 4 rubygems

Version Path
djsun-mongomapper-0.3.3 lib/mongomapper/associations/belongs_to_proxy.rb
hashrocket-mongomapper-0.3.10 lib/mongomapper/associations/belongs_to_proxy.rb
hashrocket-mongomapper-0.3.11 lib/mongomapper/associations/belongs_to_proxy.rb
hashrocket-mongomapper-0.3.12 lib/mongomapper/associations/belongs_to_proxy.rb
hashrocket-mongomapper-0.3.13 lib/mongomapper/associations/belongs_to_proxy.rb
hashrocket-mongomapper-0.3.14 lib/mongomapper/associations/belongs_to_proxy.rb
hashrocket-mongomapper-0.3.15 lib/mongomapper/associations/belongs_to_proxy.rb
hashrocket-mongomapper-0.3.3 lib/mongomapper/associations/belongs_to_proxy.rb
hashrocket-mongomapper-0.3.4.1 lib/mongomapper/associations/belongs_to_proxy.rb
hashrocket-mongomapper-0.3.4 lib/mongomapper/associations/belongs_to_proxy.rb
hashrocket-mongomapper-0.3.5 lib/mongomapper/associations/belongs_to_proxy.rb
hashrocket-mongomapper-0.3.6 lib/mongomapper/associations/belongs_to_proxy.rb
hashrocket-mongomapper-0.3.7 lib/mongomapper/associations/belongs_to_proxy.rb
hashrocket-mongomapper-0.3.8 lib/mongomapper/associations/belongs_to_proxy.rb
nirvdrum-mongomapper-0.3.3 lib/mongomapper/associations/belongs_to_proxy.rb
shingara-mongomapper-0.3.3 lib/mongomapper/associations/belongs_to_proxy.rb