Module: RC::Inclusion

Includes:
ActiveRecord::ConnectionAdapters::Quoting
Included in:
ActiveRecord::ConnectionAdapters::PostgreSQLAdapter
Defined in:
lib/rein/constraint/inclusion.rb

Instance Method Summary collapse

Instance Method Details

#add_inclusion_constraint(table, attribute, options = {}) ⇒ Object



7
8
9
10
11
12
# File 'lib/rein/constraint/inclusion.rb', line 7

def add_inclusion_constraint(table, attribute, options = {})
  name       = "#{table}_#{attribute}"
  values     = options[:in].map {|value| quote(value) }.join(", ")
  conditions = "#{attribute} IN (#{values})"
  execute("ALTER TABLE #{table} ADD CONSTRAINT #{name} CHECK (#{conditions})")
end