Module: ActiveRecord::ConnectionAdapters::ConstraintHandlers

Defined in:
lib/activerecord_constraint_handlers.rb

Overview

Constraint Handlers is a module to catch and handle the exceptions produced by failed constraints. The current implementation ties only to the create_or_update path which is after validations are done. This allows the database to have constraints but preserve the API and semantics of Model.save and Model.save!

The three hooks made available is a hook when the connection is first created. At that point, the database adapter specific module is loaded into the base. It does not work to rummage around in the database during this hook. This hook is done via ConstraintConnectionHook.

The second hook is done by the adapter specific constrait handler. The call to create_or_update is captured. If an exception is thrown, then the adapter specific handle_create_or_update_exception is called.

The third hook is also in the create_or_update. Before the call to create_or_update_witout_constraints is done, the class specific pre_fetch method is called. Again, this method is included into the class of the model at the time the connection is created.

Defined Under Namespace

Modules: Postgresql