[#4570] Replace two queries with a single query

This commit is contained in:
Eric Davis
2010-09-29 13:58:11 -07:00
parent 39c04b9896
commit d6aee43b4b

View File

@@ -125,15 +125,10 @@ class Contract < ActiveRecord::Base
end
def orphaned_time
cost_of_time_without_issue = project.time_entries.all(:conditions => {:issue_id => nil}).inject(0) do |total, time_entry|
@orphaned_time ||= project.time_entries.all(:include => [:issue => :deliverable],
:conditions => "#{Issue.table_name}.deliverable_id IS NULL OR #{TimeEntry.table_name}.issue_id IS NULL").inject(0) do |total, time_entry|
total += time_entry.cost
end
cost_of_time_without_deliverable = project.issues.all(:include => 'time_entries', :conditions => {:deliverable_id => nil}).collect(&:time_entries).flatten.inject(0) do |total, time_entry|
total += time_entry.cost
end
cost_of_time_without_issue + cost_of_time_without_deliverable
end
def to_s