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
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

Methods

Public Class

  1. configure

Public Class methods

configure (model)

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

[show source]
# File lib/sequel/plugins/column_conflicts.rb, line 32
def self.configure(model)
  model.instance_eval do
    @get_column_conflicts = {}
    @set_column_conflicts = {}
    check_column_conflicts if @dataset
  end
end