Sha256: 59acbb8a7fe3ccaa156474fc3e9450705638e8012b6341b5de88dcb225592d8e

Contents?: true

Size: 534 Bytes

Versions: 28

Compression:

Stored size: 534 Bytes

Contents

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

          owner[association.foreign_key] = id
          reset
        end

        protected
          def find_target
            return nil if owner[association.foreign_key].nil?
            klass.find_by_id(owner[association.foreign_key])
          end
      end
    end
  end
end

Version data entries

28 entries across 28 versions & 5 rubygems

Version Path
mongo_mapper-0.7.5 lib/mongo_mapper/plugins/associations/belongs_to_proxy.rb
mongo_mapper_ign-0.7.4 lib/mongo_mapper/plugins/associations/belongs_to_proxy.rb
mongo_mapper-0.7.4 lib/mongo_mapper/plugins/associations/belongs_to_proxy.rb
mongo_mapper-0.7.3 lib/mongo_mapper/plugins/associations/belongs_to_proxy.rb
numon-0.0.1 lib/mongo_mapper/plugins/associations/belongs_to_proxy.rb
mongo_mapper-0.7.2 lib/mongo_mapper/plugins/associations/belongs_to_proxy.rb
mongo_mapper-0.7.1 lib/mongo_mapper/plugins/associations/belongs_to_proxy.rb
mongo_mapper-unstable-2010.3.8 lib/mongo_mapper/plugins/associations/belongs_to_proxy.rb
mongo_mapper-unstable-2010.3.5 lib/mongo_mapper/plugins/associations/belongs_to_proxy.rb
mongo_mapper-unstable-2010.3.4 lib/mongo_mapper/plugins/associations/belongs_to_proxy.rb
mongo_mapper-unstable-2010.3.3 lib/mongo_mapper/plugins/associations/belongs_to_proxy.rb
mongo_mapper-rails3-0.7.0.1 lib/mongo_mapper/plugins/associations/belongs_to_proxy.rb
mongo_mapper-unstable-2010.2.28 lib/mongo_mapper/plugins/associations/belongs_to_proxy.rb
mongo_mapper-unstable-2010.2.27 lib/mongo_mapper/plugins/associations/belongs_to_proxy.rb
mongo_mapper-unstable-2010.2.26 lib/mongo_mapper/plugins/associations/belongs_to_proxy.rb
mongo_mapper-unstable-2010.2.25 lib/mongo_mapper/plugins/associations/belongs_to_proxy.rb
mongo_mapper-unstable-2010.2.24 lib/mongo_mapper/plugins/associations/belongs_to_proxy.rb
mongo_mapper-unstable-2010.2.23 lib/mongo_mapper/plugins/associations/belongs_to_proxy.rb
mongo_mapper-unstable-2010.2.22 lib/mongo_mapper/plugins/associations/belongs_to_proxy.rb
mongo_mapper-unstable-2010.2.19 lib/mongo_mapper/plugins/associations/belongs_to_proxy.rb