From bf76b3b286efcb4d25951bb6fcc8f59609200269 Mon Sep 17 00:00:00 2001 From: Jean-Philippe Lang Date: Sat, 1 Jun 2013 10:26:17 +0000 Subject: [PATCH] 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 --- app/models/project.rb | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) 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