Sha256: 5ede4315b423ecb1d4919396481e168555de76bed25d8a720377eeb4a765cb04
Contents?: true
Size: 874 Bytes
Versions: 1
Compression:
Stored size: 874 Bytes
Contents
require "active_record/connection_adapters/abstract/quoting" module Rein module Constraint # This module contains methods for defining inclusion constraints. module Inclusion include ActiveRecord::ConnectionAdapters::Quoting include Rein::Constraint::Options def add_inclusion_constraint(table, attribute, options = {}) name = constraint_name(table, attribute, options) values = options[:in].map { |value| quote(value) }.join(", ") conditions = conditions_with_if("#{attribute} IN (#{values})", options) execute("ALTER TABLE #{table} ADD CONSTRAINT #{name} CHECK (#{conditions})") end def remove_inclusion_constraint(table, attribute, options = {}) name = constraint_name(table, attribute, options) execute("ALTER TABLE #{table} DROP CONSTRAINT #{name}") end end end end
Version data entries
1 entries across 1 versions & 1 rubygems
Version | Path |
---|---|
rein-2.1.0 | lib/rein/constraint/inclusion.rb |