This plugin automatically detects in-place modifications to columns as well as direct modifications of the values hash.
class User < Sequel::Model plugin :modification_detection end user = User[1] user.a # => 'a' user.a << 'b' user.save_changes # UPDATE users SET a = 'ab' WHERE (id = 1)
Note that for this plugin to work correctly, the column values must correctly implement the hash method, returning the same value if the object is equal, and a different value if the object is not equal. As this solely uses hash values to check for modification, there may be cases where a modification is made and the hash value is the same, resulting in a false negative.
Note that this plugin causes a performance hit for all retrieved objects, so it shouldn’t be used in cases where performance is a primary concern.
Usage:
# Make all model subclass automatically detect column modifications Sequel::Model.plugin :modification_detection # Make the Album class automatically detect column modifications Album.plugin :modification_detection