fork_network.rb 485 Bytes
Newer Older
1 2
# frozen_string_literal: true

3
class ForkNetwork < ActiveRecord::Base
4 5
  belongs_to :root_project, class_name: 'Project'
  has_many :fork_network_members
6
  has_many :projects, through: :fork_network_members
7 8 9 10 11 12

  after_create :add_root_as_member, if: :root_project

  def add_root_as_member
    projects << root_project
  end
13 14 15 16

  def find_forks_in(other_projects)
    projects.where(id: other_projects)
  end
17 18 19 20

  def merge_requests
    MergeRequest.where(target_project: projects)
  end
21
end