module Sequel::Plugins::ModificationDetection

  1. lib/sequel/plugins/modification_detection.rb

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
user = User[1]
user.a # => 'a'
user.a << 'b'
# 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.

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.


# 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