diff options
| author | Michel Etienne | 2012-09-05 14:01:12 +0200 |
|---|---|---|
| committer | Michel Etienne | 2012-09-05 14:01:12 +0200 |
| commit | f19f90ee215a6019a6647b0b23d03a06a3458aa6 (patch) | |
| tree | 023adb2388892935af25bfbe3c00496b07d0cf84 | |
| parent | dd0369e025211d71fe071785231f3a7b2fa35561 (diff) | |
| download | chouette-core-f19f90ee215a6019a6647b0b23d03a06a3458aa6.tar.bz2 | |
remove organisation when no more user left in it
| -rw-r--r-- | app/models/user.rb | 9 |
1 files changed, 9 insertions, 0 deletions
diff --git a/app/models/user.rb b/app/models/user.rb index cc880759e..77aa02c68 100644 --- a/app/models/user.rb +++ b/app/models/user.rb @@ -14,4 +14,13 @@ class User < ActiveRecord::Base before_validation(:on => :create) do self.password ||= Devise.friendly_token.first(6) end + + # remove organisation and referentials if last user of it + after_destroy :check_destroy_organisation + def check_destroy_organisation + if organisation.users.empty? + organisation.destroy + end + end + end |
