Module: ActiveRecord::Extensions::ForeignKeys
- Included in:
- Base
- Defined in:
- lib/ar-extensions/foreign_keys.rb
Overview
Enables support for enabling and disabling foreign keys for the underlyig database connection for ActiveRecord.
This can be used with or without block form. This also uses the connection attached to the model.
Example 1, without block form
Project.foreign_keys.disable
Project.foreign_keys.enable
If you use this form you have to manually re-enable the foreign keys.
Example 2, with block form
Project.foreign_keys.disable do
# ...
end
Project.foreign_keys.enable do
# ...
end
If you use the block form the foreign keys are automatically enabled or disabled when the block exits. This currently does not restore the state of foreign keys to the state before the block was entered.
Note: If you use the disable block foreign keys will be enabled after the block exits. If you use the enable block foreign keys will be disabled after the block exits.
TODO: check the external state and restore that state when using block form.
Defined Under Namespace
Classes: ForeignKeyController
Instance Method Summary collapse
-
#foreign_keys ⇒ Object
end ForeignKeyController.
Instance Method Details
#foreign_keys ⇒ Object
end ForeignKeyController
64 65 66 |
# File 'lib/ar-extensions/foreign_keys.rb', line 64 def foreign_keys # :nodoc: ForeignKeyController.new( self ) end |