Module: CouchbaseOrm::Associations

Extended by:
ActiveSupport::Concern
Included in:
Base
Defined in:
lib/couchbase-orm/associations.rb

Defined Under Namespace

Modules: ClassMethods

Instance Method Summary collapse

Instance Method Details

#destroy_associations!Object



64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
# File 'lib/couchbase-orm/associations.rb', line 64

def destroy_associations!
    assoc = self.class.associations
    assoc.each do |name, dependent|
        next unless dependent

        model = self.__send__(name)
        if model.present?
            case dependent
            when :destroy, :delete
                if model.respond_to?(:stream)
                    model.stream { |mod| mod.__send__(dependent) }
                else
                    model.__send__(dependent)
                end
            when :restrict_with_exception
                raise RecordExists.new("#{self.class.name} instance maintains a restricted reference to #{name}", self)
            when :restrict_with_error
                # TODO::
            end
        end
    end
end

#reset_associationsObject



87
88
89
90
91
92
93
# File 'lib/couchbase-orm/associations.rb', line 87

def reset_associations
    assoc = self.class.associations
    assoc.each do |name, _|
        instance_var = :"@__assoc_#{name}"
        remove_instance_variable(instance_var) if instance_variable_defined?(instance_var)
    end
end