| Module | ActiveRecord::Extensions::ForeignKeys |
| In: |
lib/ar-extensions/foreign_keys.rb
|
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.
Project.foreign_keys.disable Project.foreign_keys.enable
If you use this form you have to manually re-enable the foreign keys.
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.