Sha256: d684a1849bade853d6a6410a3f7db85c5a59dc8abd57399607d56eb9e02dc207

Contents?: true

Size: 531 Bytes

Versions: 22

Compression:

Stored size: 531 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[reflection.foreign_key] = id
          reset
        end

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

Version data entries

22 entries across 22 versions & 3 rubygems

Version Path
drogus-mongo_mapper-0.6.10 lib/mongo_mapper/plugins/associations/belongs_to_proxy.rb
mongo_mapper-unstable-2010.2.9 lib/mongo_mapper/plugins/associations/belongs_to_proxy.rb
mongo_mapper-unstable-2010.2.8 lib/mongo_mapper/plugins/associations/belongs_to_proxy.rb
mongo_mapper-unstable-2010.2.5 lib/mongo_mapper/plugins/associations/belongs_to_proxy.rb
mongo_mapper-unstable-2010.2.4 lib/mongo_mapper/plugins/associations/belongs_to_proxy.rb
novelys_mongo_mapper-0.6.12 lib/novelys_mongo_mapper/plugins/associations/belongs_to_proxy.rb
novelys_mongo_mapper-0.6.11 lib/novelys_mongo_mapper/plugins/associations/belongs_to_proxy.rb
mongo_mapper-unstable-2010.2.3 lib/mongo_mapper/plugins/associations/belongs_to_proxy.rb
novelys_mongo_mapper-0.6.10 lib/mongo_mapper/plugins/associations/belongs_to_proxy.rb
mongo_mapper-unstable-2010.2.2 lib/mongo_mapper/plugins/associations/belongs_to_proxy.rb
mongo_mapper-unstable-2010.2.1 lib/mongo_mapper/plugins/associations/belongs_to_proxy.rb
mongo_mapper-unstable-2010.1.31 lib/mongo_mapper/plugins/associations/belongs_to_proxy.rb
mongo_mapper-unstable-2010.1.30 lib/mongo_mapper/plugins/associations/belongs_to_proxy.rb
mongo_mapper-unstable-2010.1.29 lib/mongo_mapper/plugins/associations/belongs_to_proxy.rb
mongo_mapper-unstable-2010.1.28 lib/mongo_mapper/plugins/associations/belongs_to_proxy.rb
mongo_mapper-unstable-2010.1.27 lib/mongo_mapper/plugins/associations/belongs_to_proxy.rb
mongo_mapper-unstable-2010.1.26 lib/mongo_mapper/plugins/associations/belongs_to_proxy.rb
mongo_mapper-unstable-2010.1.25 lib/mongo_mapper/plugins/associations/belongs_to_proxy.rb
mongo_mapper-unstable-2010.1.22 lib/mongo_mapper/plugins/associations/belongs_to_proxy.rb
mongo_mapper-unstable-2010.1.21 lib/mongo_mapper/plugins/associations/belongs_to_proxy.rb