Commit 6f41e3d9 authored by Tomasz Maczukin's avatar Tomasz Maczukin

Change forks method to has_many relation

parent e40c13ae
...@@ -98,8 +98,11 @@ class Project < ActiveRecord::Base ...@@ -98,8 +98,11 @@ class Project < ActiveRecord::Base
has_one :external_wiki_service, dependent: :destroy has_one :external_wiki_service, dependent: :destroy
has_one :forked_project_link, dependent: :destroy, foreign_key: "forked_to_project_id" has_one :forked_project_link, dependent: :destroy, foreign_key: "forked_to_project_id"
has_one :forked_from_project, through: :forked_project_link has_one :forked_from_project, through: :forked_project_link
has_many :forked_project_links, foreign_key: "forked_from_project_id"
has_many :forks, through: :forked_project_links, source: :forked_to_project
# Merge Requests for target project should be removed with it # Merge Requests for target project should be removed with it
has_many :merge_requests, dependent: :destroy, foreign_key: 'target_project_id' has_many :merge_requests, dependent: :destroy, foreign_key: 'target_project_id'
# Merge requests from source project should be kept when source project was removed # Merge requests from source project should be kept when source project was removed
...@@ -734,10 +737,6 @@ class Project < ActiveRecord::Base ...@@ -734,10 +737,6 @@ class Project < ActiveRecord::Base
forks.count forks.count
end end
def forks
ForkedProjectLink.where(forked_from_project_id: self.id)
end
def find_label(name) def find_label(name)
labels.find_by(name: name) labels.find_by(name: name)
end end
......
...@@ -44,8 +44,7 @@ module Projects ...@@ -44,8 +44,7 @@ module Projects
end end
def update_forks_visibility_level(new_level) def update_forks_visibility_level(new_level)
project.forks.each do |forked_link| project.forks.each do |forked_project|
forked_project = forked_link.forked_to_project
fork_level = forked_project.visibility_level fork_level = forked_project.visibility_level
if fork_level > new_level.to_i if fork_level > new_level.to_i
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment