Module: ActiveRecord::ConnectionAdapters::Constraints
- Defined in:
- lib/activerecord_constraints.rb
Overview
Module that will be included in other modules to reduce duplication. It implements the conversion from a list of options that specify a constraint to the SQL statement that implements the constraint.
A constraint is broken into parts:
-
An optional constraint name
-
One of:
-
unique constraint
-
foreign key constraint
-
check constraint
-
-
An optional deferrable clause
-
An optional initially clause
There are two places to declare a constraint. PostgreSQL calls these column constraints and table constraints. A column constraint can have a few things that a table constraint can not such as not null or null constraints. Those are handled elsewhere in Active Record although they might get moved in to here since this code allows those constraints to be named which may have some advantages.
The SQL syntax for the column and table constraints are very similar so the routines handle both with a flag that specifies if the routine is being called to create a column constraint or a table constraint.
The name of a constraint can be specified with either a :name => "constraint_name"
option or, for example, :unique => "constraint_name"
. The main advantage to this is to allow a multiple named constraints in the same column specification.
Defined Under Namespace
Modules: Abstract, Postgresql, Sql