From 521eaa79cb56a86e83876d95fa510ca13aebfbdf Mon Sep 17 00:00:00 2001 From: Jean-Philippe Lang Date: Sun, 24 Jul 2011 15:34:41 +0000 Subject: Ability to load relations on /issues API (#7366). git-svn-id: svn+ssh://rubyforge.org/var/svn/redmine/trunk@6313 e93f8b46-1217-0410-a6f0-8f06a7374b81 --- app/models/issue.rb | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) (limited to 'app/models/issue.rb') diff --git a/app/models/issue.rb b/app/models/issue.rb index 48a0afb2a..ccd326552 100644 --- a/app/models/issue.rb +++ b/app/models/issue.rb @@ -508,7 +508,17 @@ class Issue < ActiveRecord::Base end def relations - (relations_from + relations_to).sort + @relations ||= (relations_from + relations_to).sort + end + + # Preloads relations for a collection of issues + def self.load_relations(issues) + if issues.any? + relations = IssueRelation.all(:conditions => ["issue_from_id IN (:ids) OR issue_to_id IN (:ids)", {:ids => issues.map(&:id)}]) + issues.each do |issue| + issue.instance_variable_set "@relations", relations.select {|r| r.issue_from_id == issue.id || r.issue_to_id == issue.id} + end + end end # Finds an issue relation given its id. -- cgit v1.2.3