3 ms·
ActiveRecord doesn't even support constraints in the first place.
by effn 13y ago
ActiveRecord doesn't even support constraints in the first place.
- joevandyk 13y agoWhat do you mean by "support constraints"? If I, for example, violate a unique index, a ActiveRecord::RecordNotUnique exception is raised.
- mjhoy 13y agoIs that true? I might be wrong about this, but I think ActiveRecord checks for uniqueness (and other constraints) in application code, generating an extra database query if needed. If you _actually_ violate the unique index, a PGError is raised (if using postgres).
- FooBarWidget 13y agoNo. ActiveRecord checks for constraints on top of what the database offers. You are free to specify database constraints if you like. In older versions of ActiveRecord, uniqueness errors generate a generic database exception. In recent versions, uniqueness errors generate the specific exception RecordNotUnique.
- pjungwir 13y agoShameless plug: here is a gem I wrote to manage foreign keys and CHECK constraints (and also indexes) in a Rails project: https://github.com/pjungwir/db_leftovers https://github.com/pjungwir/db_leftovers