2018-11-18 11:00:15 +05:30
|
|
|
# frozen_string_literal: true
|
|
|
|
|
2019-07-07 11:18:12 +05:30
|
|
|
class ForkNetworkMember < ApplicationRecord
|
2018-03-17 18:26:18 +05:30
|
|
|
belongs_to :fork_network
|
|
|
|
belongs_to :project
|
|
|
|
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
|