Module: Sequel::Plugins::ColumnConflicts

Defined in:
lib/sequel/plugins/column_conflicts.rb

Overview

The column_conflicts plugin overrides Model#get_column_value and #set_column_value to automatically handle column names that conflict with Ruby/Sequel method names.

By default, Model#get_column_value and #set_column_value just call send, this plugin overrides the methods and gets/sets the value directly in the values hash if the column name conflicts with an existing Sequel::Model instance method name.

Checking for column conflicts causes a performance hit, which is why Sequel does not enable such checks by default.

When using this plugin, you can manually update the columns used. This may be useful if the columns conflict with one of your custom methods, instead of a method defined in Sequel::Model:

Album.plugin :column_conflicts
Album.get_column_conflict!(:column)
Album.set_column_conflict!(:other_column)

Usage:

# Make all model's handle column conflicts automatically (called before loading subclasses)
Sequel::Model.plugin :column_conflicts

# Make the Album class handle column conflicts automatically
Album.plugin :column_conflicts

Defined Under Namespace

Modules: ClassMethods, InstanceMethods

Class Method Summary collapse

Class Method Details

.configure(model) ⇒ Object

Check for column conflicts on the current model if the model has a dataset.



33
34
35
36
37
38
39
# File 'lib/sequel/plugins/column_conflicts.rb', line 33

def self.configure(model)
  model.instance_eval do
    @get_column_conflicts = {}
    @set_column_conflicts = {}
    check_column_conflicts if @dataset
  end
end