Plugins -

StarAdd to favorites

dependent => :protect option

Adds a new option :protect for the parameter :depends from has_many method. This option forbids destroying records with associated records in a association created with :dependent => :protect option, more or less like ON DELETE RESTRICT SQL statement. If you try to destroy a record with associated records it will raise a ActiveRecord::ReferentialIntegrityProtectionError (defined also in this plugin).

Based on the idea and the code from diego.algorta@gmail.com (don’t mail him if you have problems with the plugin, he only was the ideologist) in Ruby on Rails ticket #3837 (http://dev.rubyonrails.org/ticket/3837).

You can download this plugin at:

http://svn.ruido-blanco.net/dependent_protect/trunk

Author

Daniel Rodríguez Troitiño , based on the ideas and the code from Diego Algorta.

Daniel Rodríguez Troitiño

http://ruido-blanco.net/blog/rails-dependent-protect-plugin-english

http://svn.ruido-blanco.net/dependent_protect/trunk

Rails' (MIT)

  • Currently 4.8/5 Stars.
  • 1
  • 2
  • 3
  • 4
  • 5

Model

Tags

Comments

Add a comment
Daniel Rodríguez Troitiño 9 Aug 2006

Try with ActiveRecord::ReferentialIntegrityProtectionError.

All errors defined inside ActiveRecord seems to need fully qualified.

Swartz 8 Aug 2006

The only question I have is how to catch the exception being created?

I've tried rescue-ing ReferentialIntegrityProtectionError but all i get is the following error:

uninitialized constant ReferentialIntegrityProtectionError

Search Plugins

Query syntax

Plugins by Category

Sponsors

Rails Kits: Get Code. Get Moving.

Have a comment?