-
Notifications
You must be signed in to change notification settings - Fork 0
/
README
54 lines (37 loc) · 2.01 KB
/
README
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
= Schema Validations
Schema Validations is a plugin that reads various constraints defined against
columns in your database and applies the closest matching rails validation.
(Ala Dave Thomas' Keynote.)
Over and above installing the plugin, no further action is required for the
validations to take effect; the database schema constraints will be read and
applied as validations when your ActiveRecord model classes are loaded; just
like magic.
The plugin supports the following constraints:
* <code>NOT NULL</code> is converted to +validates_presence_of+ (including +belongs_to+ associations);
* Numbers are checked using +validates_numericality_of+ (including <code>:only_integer => true</code>);
* String lengths are checked using +validates_length_of+;
* Single-column unique indexes are converted to +validates_uniqueness_of+; and
* Multi-column unique indexes are converted to +validates_uniqueness_of+ with +scope+.
For multi-column unique indexes the column validated for uniqueness is either
the last column not ending in '_id' or simply the last column. This follows the
typical composite unique index column ordering where the scoping is specified
first but will attempt to find the last non-foreign-key column just-in-case.
For example, either of the following two statements in a schema migration script:
add_index :states, [:country_id, :name], :unique => true
add_index :states, [:name, :country_id], :unique => true
would result in:
validates_uniqueness_of :name, :scope => [:country_id]
Validation may be limited to specific columns by calling <code>schema_validations</code> from within
your model class, passing either a single column:
class Country < ActiveRecord::Base
schema_validations :only => :name
end
or an array of columns:
class Country < ActiveRecord::Base
schema_validations :except => [:isocode, :iddcode]
end
=== Dependencies
* RedHill on Rails Core (redhillonrails_core).
=== License
This plugin is copyright 2006 by RedHill Consulting, Pty. Ltd. and is released
under the MIT license.