From 3e28dc669b014db811c0de673a090adf54f42bc1 Mon Sep 17 00:00:00 2001 From: Jean-Philippe Lang Date: Sat, 16 Dec 2006 17:33:31 +0000 Subject: [PATCH] various eager loadings added git-svn-id: http://redmine.rubyforge.org/svn/trunk@98 e93f8b46-1217-0410-a6f0-8f06a7374b81 --- app/controllers/application.rb | 2 +- app/controllers/projects_controller.rb | 8 ++++---- app/models/project.rb | 2 +- 3 files changed, 6 insertions(+), 6 deletions(-) diff --git a/app/controllers/application.rb b/app/controllers/application.rb index 45c3206ce..483d0a102 100644 --- a/app/controllers/application.rb +++ b/app/controllers/application.rb @@ -25,7 +25,7 @@ class ApplicationController < ActionController::Base def logged_in_user if session[:user_id] - @logged_in_user ||= User.find(session[:user_id], :include => :memberships) + @logged_in_user ||= User.find(session[:user_id]) else nil end diff --git a/app/controllers/projects_controller.rb b/app/controllers/projects_controller.rb index a31b7ec55..4151e734c 100644 --- a/app/controllers/projects_controller.rb +++ b/app/controllers/projects_controller.rb @@ -175,7 +175,7 @@ class ProjectsController < ApplicationController # Show documents list of @project def list_documents - @documents = @project.documents + @documents = @project.documents.find :all, :include => :category end # Add a new issue to @project @@ -398,7 +398,7 @@ class ProjectsController < ApplicationController end unless params[:show_news] == "0" - @project.news.find(:all, :conditions => ["news.created_on>=? and news.created_on<=?", @date_from, @date_to] ).each { |i| + @project.news.find(:all, :conditions => ["news.created_on>=? and news.created_on<=?", @date_from, @date_to], :include => :author ).each { |i| @events_by_day[i.created_on.to_date] ||= [] @events_by_day[i.created_on.to_date] << i } @@ -406,7 +406,7 @@ class ProjectsController < ApplicationController end unless params[:show_files] == "0" - Attachment.find(:all, :select => "attachments.*", :joins => "LEFT JOIN versions ON versions.id = attachments.container_id", :conditions => ["attachments.container_type='Version' and versions.project_id=? and attachments.created_on>=? and attachments.created_on<=?", @project.id, @date_from, @date_to] ).each { |i| + Attachment.find(:all, :select => "attachments.*", :joins => "LEFT JOIN versions ON versions.id = attachments.container_id", :conditions => ["attachments.container_type='Version' and versions.project_id=? and attachments.created_on>=? and attachments.created_on<=?", @project.id, @date_from, @date_to], :include => :author ).each { |i| @events_by_day[i.created_on.to_date] ||= [] @events_by_day[i.created_on.to_date] << i } @@ -418,7 +418,7 @@ class ProjectsController < ApplicationController @events_by_day[i.created_on.to_date] ||= [] @events_by_day[i.created_on.to_date] << i } - Attachment.find(:all, :select => "attachments.*", :joins => "LEFT JOIN documents ON documents.id = attachments.container_id", :conditions => ["attachments.container_type='Document' and documents.project_id=? and attachments.created_on>=? and attachments.created_on<=?", @project.id, @date_from, @date_to] ).each { |i| + Attachment.find(:all, :select => "attachments.*", :joins => "LEFT JOIN documents ON documents.id = attachments.container_id", :conditions => ["attachments.container_type='Document' and documents.project_id=? and attachments.created_on>=? and attachments.created_on<=?", @project.id, @date_from, @date_to], :include => :author ).each { |i| @events_by_day[i.created_on.to_date] ||= [] @events_by_day[i.created_on.to_date] << i } diff --git a/app/models/project.rb b/app/models/project.rb index cf17f0f5a..83197dfde 100644 --- a/app/models/project.rb +++ b/app/models/project.rb @@ -20,7 +20,7 @@ class Project < ActiveRecord::Base has_many :members, :dependent => true has_many :users, :through => :members has_many :custom_values, :dependent => true, :as => :customized - has_many :issues, :dependent => true, :order => "issues.created_on DESC", :include => :status + has_many :issues, :dependent => true, :order => "issues.created_on DESC", :include => [:status, :tracker] has_many :queries, :dependent => true has_many :documents, :dependent => true has_many :news, :dependent => true, :include => :author