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

.apply(model) ⇒ Object



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

def self.apply(model)
  model.instance_exec do
    @get_column_conflicts = {}
    @set_column_conflicts = {}
  end
end

.configure(model) ⇒ Object

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



40
41
42
43
44
# File 'lib/sequel/plugins/column_conflicts.rb', line 40

def self.configure(model)
  model.instance_exec do
    check_column_conflicts if @dataset
  end
end