2018-07-25 05:30:33 -04:00
|
|
|
# frozen_string_literal: true
|
|
|
|
|
2017-09-28 10:38:12 -04:00
|
|
|
class ForkNetworkMember < ActiveRecord::Base
|
|
|
|
belongs_to :fork_network
|
|
|
|
belongs_to :project
|
|
|
|
belongs_to :forked_from_project, class_name: 'Project'
|
|
|
|
|
|
|
|
validates :fork_network, :project, presence: true
|
2017-11-13 12:13:03 -05:00
|
|
|
|
|
|
|
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
|
2017-09-28 10:38:12 -04:00
|
|
|
end
|