module Sequel::Plugins::ColumnConflicts

  1. lib/sequel/plugins/column_conflicts.rb

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


# 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


Public Class

  1. apply
  2. configure

Public Class methods

[show source]
   # File lib/sequel/plugins/column_conflicts.rb
32 def self.apply(model)
33   model.instance_exec do
34     @get_column_conflicts = {}
35     @set_column_conflicts = {}
36   end
37 end

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

[show source]
   # File lib/sequel/plugins/column_conflicts.rb
40 def self.configure(model)
41   model.instance_exec do
42     check_column_conflicts if @dataset
43   end
44 end