Sha256: 3ab91652fbe63a7f77051048e4b89b9deaccd1b047b28117d8a906dcfad7b386

Contents?: true

Size: 1.07 KB

Versions: 21

Compression:

Stored size: 1.07 KB

Contents

# encoding: UTF-8
module MongoMapper
  module Plugins
    module Associations
      class OneAssociation < SingleAssociation
        def embeddable?
          klass.embeddable?
        end

        def proxy_class
          @proxy_class ||=
            if klass.embeddable?
              polymorphic? ? OneEmbeddedPolymorphicProxy : OneEmbeddedProxy
            elsif as?
              OneAsProxy
            else
              OneProxy
            end
        end

        def setup(model)
          super

          association = self
          options = self.options

          model.before_destroy do
            if !association.embeddable?
              proxy = self.get_proxy(association)

              unless proxy.nil?
                case options[:dependent]
                  when :destroy then proxy.destroy
                  when :delete  then proxy.delete
                  else proxy.nullify
                end
              end
            end
          end
        end

        def autosave?
          options.fetch(:autosave, embeddable?)
        end
      end
    end
  end
end

Version data entries

21 entries across 21 versions & 3 rubygems

Version Path
mongo_mapper-0.17.0 lib/mongo_mapper/plugins/associations/one_association.rb
mongo_mapper-0.16.0 lib/mongo_mapper/plugins/associations/one_association.rb
mongo_mapper-0.15.6 lib/mongo_mapper/plugins/associations/one_association.rb
mongo_mapper-0.15.5 lib/mongo_mapper/plugins/associations/one_association.rb
mongo_mapper-0.15.4 lib/mongo_mapper/plugins/associations/one_association.rb
mongo_mapper-0.15.3 lib/mongo_mapper/plugins/associations/one_association.rb
mongo_mapper-0.15.2 lib/mongo_mapper/plugins/associations/one_association.rb
mongo_mapper-0.15.1 lib/mongo_mapper/plugins/associations/one_association.rb
mongo_mapper-0.15.0 lib/mongo_mapper/plugins/associations/one_association.rb
mongo_mapper-0.14.0 lib/mongo_mapper/plugins/associations/one_association.rb
mongo_mapper-0.14.0.rc1 lib/mongo_mapper/plugins/associations/one_association.rb
mongo_mapper-0.13.1 lib/mongo_mapper/plugins/associations/one_association.rb
mongo_mapper-0.13.0 lib/mongo_mapper/plugins/associations/one_association.rb
mongo_mapper-0.13.0.beta2 lib/mongo_mapper/plugins/associations/one_association.rb
mongo_mapper-0.13.0.beta1 lib/mongo_mapper/plugins/associations/one_association.rb
mongo_mapper-0.12.0 lib/mongo_mapper/plugins/associations/one_association.rb
lookout-mongo_mapper-0.11.3 lib/mongo_mapper/plugins/associations/one_association.rb
mongo_mapper-0.11.2 lib/mongo_mapper/plugins/associations/one_association.rb
jamieorc-mongo_mapper-0.11.1.1 lib/mongo_mapper/plugins/associations/one_association.rb
mongo_mapper-0.11.1 lib/mongo_mapper/plugins/associations/one_association.rb