module Sequel::Plugins::SkipSavingColumns

  1. lib/sequel/plugins/skip_saving_columns.rb

The skip_saving_columms plugin allows skipping specific columns when saving. By default, it skips columns that the database schema indicates are generated columns:

# Assume id column, name column, and id2 generated column
album = Album[1] # => 1 # => 'X'
album.id2 # => 2
# UPDATE album SET name = 'X' WHERE (id = 1)

You can override which columns will be skipped:

Album.skip_saving_columns = [:name]
# UPDATE album SET id2 = 2 WHERE (id = 1)

The skipping happens for all usage of Model#save and callers of it (e.g. Model.create, Model.update). When using the plugin, the only way to get it to save a column marked for skipping is to explicitly specify it: [:name, :id2])
# UPDATE album SET name = 'X', id2 = 2 WHERE (id = 1)


# Support skipping saving columns in all Sequel::Model subclasses
# (called before loading subclasses)
Sequel::Model.plugin :skip_saving_columns

# Support skipping saving columns in the Album class
Album.plugin :skip_saving_columns


Public Class

  1. configure

Public Class methods


Setup skipping of the generated columns for a model with an existing dataset.

[show source]
   # File lib/sequel/plugins/skip_saving_columns.rb
41 def self.configure(mod)
42   mod.instance_exec do
43     set_skip_saving_generated_columns if @dataset
44   end
45 end