Sha256: 01fb5b1451cff35390ce3667695159b35487bd137e7f0a16b950953358fec803
Contents?: true
Size: 593 Bytes
Versions: 2
Compression:
Stored size: 593 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 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 end end end
Version data entries
2 entries across 2 versions & 1 rubygems
Version | Path |
---|---|
rein-1.1.0 | lib/rein/constraint/inclusion.rb |
rein-1.0.0 | lib/rein/constraint/inclusion.rb |