From: Jean-Philippe Lang Date: Sat, 1 Jun 2013 10:26:17 +0000 (+0000) Subject: Project#all_issue_custom_fields now returns a scope. X-Git-Tag: 2.4.0~292 X-Git-Url: https://source.dussan.org/?a=commitdiff_plain;h=bf76b3b286efcb4d25951bb6fcc8f59609200269;p=redmine.git Project#all_issue_custom_fields now returns a scope. git-svn-id: svn+ssh://rubyforge.org/var/svn/redmine/trunk@11916 e93f8b46-1217-0410-a6f0-8f06a7374b81 --- diff --git a/app/models/project.rb b/app/models/project.rb index 6e31eafd4..f5ae92f9b 100644 --- a/app/models/project.rb +++ b/app/models/project.rb @@ -513,10 +513,14 @@ class Project < ActiveRecord::Base members.select {|m| m.principal.present? && (m.mail_notification? || m.principal.mail_notification == 'all')}.collect {|m| m.principal} end - # Returns an array of all custom fields enabled for project issues + # Returns a scope of all custom fields enabled for project issues # (explictly associated custom fields and custom fields enabled for all projects) def all_issue_custom_fields - @all_issue_custom_fields ||= (IssueCustomField.for_all + issue_custom_fields).uniq.sort + @all_issue_custom_fields ||= IssueCustomField. + sorted. + where("is_for_all = ? OR id IN (SELECT DISTINCT cfp.custom_field_id" + + " FROM #{table_name_prefix}custom_fields_projects#{table_name_suffix} cfp" + + " WHERE cfp.project_id = ?)", true, id) end # Returns an array of all custom fields enabled for project time entries