summaryrefslogtreecommitdiffstats
path: root/app/models/issue.rb
diff options
context:
space:
mode:
authorJean-Philippe Lang <jp_lang@yahoo.fr>2011-07-24 15:34:41 +0000
committerJean-Philippe Lang <jp_lang@yahoo.fr>2011-07-24 15:34:41 +0000
commit521eaa79cb56a86e83876d95fa510ca13aebfbdf (patch)
tree94e033dcd604795d60616520597a678b1fa96635 /app/models/issue.rb
parent49900051ea2b404161dae568eeaec6f26bbe0c9d (diff)
downloadredmine-521eaa79cb56a86e83876d95fa510ca13aebfbdf.tar.gz
redmine-521eaa79cb56a86e83876d95fa510ca13aebfbdf.zip
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
Diffstat (limited to 'app/models/issue.rb')
-rw-r--r--app/models/issue.rb12
1 files changed, 11 insertions, 1 deletions
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.