module Denormalized::Core::ClassMethods

Public Instance Methods

denormalized_attribute?(name) click to toggle source
# File lib/denormalized/core.rb, line 119
def denormalized_attribute?(name)
  name = name.to_sym if name.is_a?(String)

  if name.is_a?(Symbol)
    return denormalized_configuration[:columns_hash][name]
  end

  Rails.logger.warn '[DENORMALIZED]: Symbol expected, instead received ' + name.class.to_s
  false
end
update(id, attributes) click to toggle source
Calls superclass method
# File lib/denormalized/core.rb, line 130
def update(id, attributes)
  if attributes.keys.any? { |name| denormalized_attribute?(name) }
    subjects = base_class.where(id: id) # we will let super handle errors if subject doesn't exist

    if subjects.any?
      subjects.each do |subject|
        gifted_attributes = subject.extract_denormalized_attributes(attributes)

        denormalized_configuration[:tables].each do |table|
          subject.denormalized_action(
            table: table,
            where_attrs: subject.extract_existing_denormalized_attributes(attributes),
            method: :update,
            args: gifted_attributes
          )
        end
      end
    end
  end

  super
end
update_all(updates) click to toggle source
Calls superclass method
# File lib/denormalized/core.rb, line 153
def update_all(updates)
  if updates.keys.any? { |name| denormalized_attribute?(name) }
    Rails.logger.warn '[DENORMALIZED]: Unable to update followers when using `update_all` -- orphans may have been created'
  end

  super
end