diff options
| -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 |
