Something that I believe would be useful to prevent overzealous “updates” via touch would be to allow a lambda to be specified to determine if the touch should occur or not.
class Client
belongs_to :project, touch: → {|rec| rec.name_changed?}
end
In this case, the project association is only “touched” if only the client name changes. This way if there’s a lot of client data that has no value to the project object and the project is only concerned with a change to just one client attribute (for example) this would only trigger the touch in that case.
Since an attribute can be specified for touch, then perhaps the option should be called touch_if and the touch is always performed when the main object is destroyed.
class Client belongs_to :project, touch: true, touch_if: → {|rec| rec.name_changed?}
end
Thoughts?