diff options
author | Bob Van Landuyt <bob@vanlanduyt.co> | 2017-11-13 20:13:03 +0300 |
---|---|---|
committer | Bob Van Landuyt <bob@vanlanduyt.co> | 2017-11-17 14:58:15 +0300 |
commit | 8b426b63d6044746a71a63b07a709bdc9a2ee832 (patch) | |
tree | 475e0a6346c21e8338510755eb4e808e26e52fb8 /app/models | |
parent | 4aa18590b3af27c9cb3cd3c2fc8c0a70e9a8758e (diff) |
Delete the fork network when removing the last membership
Diffstat (limited to 'app/models')
-rw-r--r-- | app/models/fork_network_member.rb | 10 |
1 files changed, 10 insertions, 0 deletions
diff --git a/app/models/fork_network_member.rb b/app/models/fork_network_member.rb index 6a9b52a1ef8..eb9417dc34f 100644 --- a/app/models/fork_network_member.rb +++ b/app/models/fork_network_member.rb @@ -4,4 +4,14 @@ class ForkNetworkMember < ActiveRecord::Base belongs_to :forked_from_project, class_name: 'Project' validates :fork_network, :project, presence: true + + after_destroy :cleanup_fork_network + + private + + def cleanup_fork_network + # Explicitly using `#count` makes sure we have the correct number if the + # relation was loaded in the fork_network. + fork_network.destroy if fork_network.fork_network_members.count == 0 + end end |