Sha256: d5ad95d5c9e785edc4f59561ff3d61c8cc623a00ba955bcb34222e8ff0bd9c7d

Contents?: true

Size: 719 Bytes

Versions: 1

Compression:

Stored size: 719 Bytes

Contents

module Rein
  module Constraint
    # This module contains methods for defining null constraints.
    module Null
      include ActiveRecord::ConnectionAdapters::Quoting
      include Rein::Constraint::Options

      def add_null_constraint(table, attribute, options = {})
        name = constraint_name(table, attribute, options)
        conditions = conditions_with_if("#{attribute} IS NOT NULL", options)
        execute("ALTER TABLE #{table} ADD CONSTRAINT #{name} CHECK (#{conditions})")
      end

      def remove_null_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/null.rb