module CouchbaseOrm::Associations

Public Instance Methods

destroy_associations!() click to toggle source
# 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_associations() click to toggle source
# 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