module Sequel::Plugins::SplitValues

  1. lib/sequel/plugins/split_values.rb

The split_values plugin splits the values hash retreived from the database, and moves keys from the values hash that are not columns in the model’s dataset to a separate hash. This makes it so the values hash only stores columns from the model’s dataset.

Among other things, this allows you to save model objects even if they were retrieved with additional columns, and have equality comparisons with other instances not care about non-column values.


class Album < Sequel::Model
  plugin :split_values
a1 = Album[1]
a2 = Album.select_append(, :exists))[1] # => 'Album Name' # => 'Album Name'
a1[:exists] # => nil
a2[:exists] # => true
a1 == a2 # => true
a2.values # => {:id=>1, :name=>'Album Name'} # Works


# Make all model subclass instances split values
# (called before loading subclasses)
Sequel::Model.plugin :split_values

# Make the Album class split values
Album.plugin :split_values