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
Classes and Modules
Public Class methods
# 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.
# 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