module Sequel::Plugins::UpdateRefresh

  1. lib/sequel/plugins/update_refresh.rb

The update_refresh plugin makes the model class refresh the object after updating. By default, Sequel only refreshes automatically after inserting new rows, not after updating. However, if you are using triggers to modify the contents of updated rows, it can be helpful to immediately get the current data after updating.

If the dataset supports UPDATE RETURNING, this plugin will use it so that it can retrieve the current data in the same query it uses for the update.


# Make all model subclasses refresh after update
Sequel::Model.plugin :update_refresh

# Make the Album class refresh after update
Album.plugin :update_refresh

As a performance optimisation, if you know only specific columns will have changed, you can specify them to the columns option. This can be a performance gain if it would avoid pointlessly comparing many other columns. Note that this option currently only has an effect if the dataset supports RETURNING.

# Only include the artist column in RETURNING
Album.plugin :update_refresh, columns: :artist

# Only include the artist and title columns in RETURNING
Album.plugin :update_refresh, columns: [:artist, :title]


Public Class

  1. configure

Public Class methods

configure(model, opts=OPTS)

Set the specific columns to refresh, if the :columns option is provided.

[show source]
   # File lib/sequel/plugins/update_refresh.rb
40 def self.configure(model, opts=OPTS)
41   model.instance_exec do
42     @update_refresh_columns = Array(opts[:columns]) || []
43   end
44 end