Sha256: d41cacee662017b136faa32cb2695522b3f8dfab66829ceba9a57596e7366e8b

Contents?: true

Size: 470 Bytes

Versions: 11

Compression:

Stored size: 470 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

11 entries across 11 versions & 4 rubygems

Version Path
mongo_mapper-0.6.6 lib/mongo_mapper/associations/belongs_to_proxy.rb
mongo_mapper-unstable-2009.12.4 lib/mongo_mapper/associations/belongs_to_proxy.rb
danielharan-mongo_mapper-0.6.5 lib/mongo_mapper/associations/belongs_to_proxy.rb
mongo_mapper-0.6.5 lib/mongo_mapper/associations/belongs_to_proxy.rb
webbynode-mongo_mapper-0.6.4 lib/mongo_mapper/associations/belongs_to_proxy.rb
mongo_mapper-0.6.4 lib/mongo_mapper/associations/belongs_to_proxy.rb
mongo_mapper-0.6.3 lib/mongo_mapper/associations/belongs_to_proxy.rb
mongo_mapper-0.6.2 lib/mongo_mapper/associations/belongs_to_proxy.rb
mongo_mapper-0.6.1 lib/mongo_mapper/associations/belongs_to_proxy.rb
mongo_mapper-unstable-2009.11.18 lib/mongo_mapper/associations/belongs_to_proxy.rb
mongo_mapper-0.6.0 lib/mongo_mapper/associations/belongs_to_proxy.rb