File: fork_network_member.rb

package info (click to toggle)
gitlab 17.6.5-19
  • links: PTS, VCS
  • area: main
  • in suites: sid
  • size: 629,368 kB
  • sloc: ruby: 1,915,304; javascript: 557,307; sql: 60,639; xml: 6,509; sh: 4,567; makefile: 1,239; python: 406
file content (22 lines) | stat: -rw-r--r-- 657 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
# frozen_string_literal: true

class ForkNetworkMember < ApplicationRecord
  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

  scope :by_projects, ->(ids) { where(project_id: ids) }
  scope :with_fork_network, -> { joins(:fork_network).includes(: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