diff options
author | Jeremy Kemper <jeremy@bitsweat.net> | 2005-11-08 10:19:09 +0000 |
---|---|---|
committer | Jeremy Kemper <jeremy@bitsweat.net> | 2005-11-08 10:19:09 +0000 |
commit | 35b4bdcff0e697765b562a74bd881e78de97f4d1 (patch) | |
tree | 15d1e68d1fd4fa2f4a4b40e133716b0cada078cf /activerecord/test/fixtures | |
parent | c54b51fa7e6fd51f89cd74c9b2b2f144f2229ee9 (diff) | |
download | rails-35b4bdcff0e697765b562a74bd881e78de97f4d1.tar.gz rails-35b4bdcff0e697765b562a74bd881e78de97f4d1.tar.bz2 rails-35b4bdcff0e697765b562a74bd881e78de97f4d1.zip |
Destroy associated has_and_belongs_to_many records after all before_destroy callbacks but before destroy. This allows you to act on the habtm association as you please while preserving referential integrity. Closes #2065.
git-svn-id: http://svn-commit.rubyonrails.org/rails/trunk@2940 5ecf4fe2-1ee6-0310-87b1-e25e094e27de
Diffstat (limited to 'activerecord/test/fixtures')
-rw-r--r-- | activerecord/test/fixtures/developer.rb | 10 |
1 files changed, 10 insertions, 0 deletions
diff --git a/activerecord/test/fixtures/developer.rb b/activerecord/test/fixtures/developer.rb index ce65ff78c0..29555d926a 100644 --- a/activerecord/test/fixtures/developer.rb +++ b/activerecord/test/fixtures/developer.rb @@ -28,3 +28,13 @@ class DeveloperWithAggregate < ActiveRecord::Base self.table_name = 'developers' composed_of :salary, :class_name => 'DeveloperSalary', :mapping => [%w(salary amount)] end + +class DeveloperWithBeforeDestroyRaise < ActiveRecord::Base + self.table_name = 'developers' + has_and_belongs_to_many :projects, :join_table => 'developers_projects', :foreign_key => 'developer_id' + before_destroy :raise_if_projects_empty! + + def raise_if_projects_empty! + raise if projects.empty? + end +end |