module ActiverecordTouchy::Associations::ClassMethods

Public Instance Methods

has_many(name, scope = nil, **options, &extension) click to toggle source
Calls superclass method
# File lib/activerecord_touchy/associations.rb, line 10
def has_many(name, scope = nil, **options, &extension)
  touch = (scope.is_a?(Hash) ? scope : options).delete(:touch)
  result = super

  if touch
    after_commit do
      public_send(name).update_all(updated_at: Time.now.utc)
    end
  end

  result
end
has_one(name, scope = nil, **options) click to toggle source
Calls superclass method
# File lib/activerecord_touchy/associations.rb, line 23
def has_one(name, scope = nil, **options)
  touch = (scope.is_a?(Hash) ? scope : options).delete(:touch)
  result = super

  if touch
    after_commit do
      public_send(name)&.touch
    end
  end

  result
end