Sha256: f599b62529d6b99b8267cb1578df4ef5d776551b7a62bf786df33c82bd1bf446

Contents?: true

Size: 492 Bytes

Versions: 10

Compression:

Stored size: 492 Bytes

Contents

module MongoMapper
  module Plugins
    module Associations
      class BelongsToProxy < Proxy
        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.first(:id => owner[reflection.foreign_key])
          end
      end
    end
  end
end

Version data entries

10 entries across 10 versions & 2 rubygems

Version Path
jmonteiro-mongo_mapper-0.1.7 lib/mongo_mapper/plugins/associations/belongs_to_proxy.rb
mongo_mapper-unstable-2010.1.18 lib/mongo_mapper/plugins/associations/belongs_to_proxy.rb
jmonteiro-mongo_mapper-0.1.6 lib/mongo_mapper/plugins/associations/belongs_to_proxy.rb
jmonteiro-mongo_mapper-0.1.5 lib/mongo_mapper/plugins/associations/belongs_to_proxy.rb
mongo_mapper-unstable-2010.1.17 lib/mongo_mapper/plugins/associations/belongs_to_proxy.rb
jmonteiro-mongo_mapper-0.1.4 lib/mongo_mapper/plugins/associations/belongs_to_proxy.rb
jmonteiro-mongo_mapper-0.1.2 lib/mongo_mapper/plugins/associations/belongs_to_proxy.rb
jmonteiro-mongo_mapper-0.1.1 lib/mongo_mapper/plugins/associations/belongs_to_proxy.rb
jmonteiro-mongo_mapper-0.1.0 lib/mongo_mapper/plugins/associations/belongs_to_proxy.rb
mongo_mapper-unstable-2010.1.12 lib/mongo_mapper/plugins/associations/belongs_to_proxy.rb