"references" is needed for includes, but not needed for joins. git-svn-id: http://svn.redmine.org/redmine/trunk@13501 e93f8b46-1217-0410-a6f0-8f06a7374b81tags/3.0.0
@@ -46,7 +46,6 @@ class BoardsController < ApplicationController | |||
@topics = @board.topics. | |||
reorder("#{Message.table_name}.sticky DESC"). | |||
joins("LEFT OUTER JOIN #{Message.table_name} last_replies_messages ON last_replies_messages.id = #{Message.table_name}.last_reply_id"). | |||
references(:last_reply). | |||
limit(@topic_pages.per_page). | |||
offset(@topic_pages.offset). | |||
order(sort_clause). |
@@ -69,7 +69,6 @@ module MyHelper | |||
TimeEntry. | |||
where("#{TimeEntry.table_name}.user_id = ? AND #{TimeEntry.table_name}.spent_on BETWEEN ? AND ?", User.current.id, Date.today - 6, Date.today). | |||
joins(:activity, :project, {:issue => [:tracker, :status]}). | |||
references(:activity, :project, {:issue => [:tracker, :status]}). | |||
order("#{TimeEntry.table_name}.spent_on DESC, #{Project.table_name}.name ASC, #{Tracker.table_name}.position ASC, #{Issue.table_name}.id ASC"). | |||
to_a | |||
end |
@@ -32,7 +32,6 @@ class Board < ActiveRecord::Base | |||
scope :visible, lambda {|*args| | |||
joins(:project). | |||
references(:project). | |||
where(Project.allowed_to_condition(args.shift || User.current, :view_messages, *args)) | |||
} | |||
@@ -50,7 +50,6 @@ class Changeset < ActiveRecord::Base | |||
scope :visible, lambda {|*args| | |||
joins(:repository => :project). | |||
references(:repository => :project). | |||
where(Project.allowed_to_condition(args.shift || User.current, :view_changesets, *args)) | |||
} | |||
@@ -36,7 +36,6 @@ class Document < ActiveRecord::Base | |||
scope :visible, lambda {|*args| | |||
joins(:project). | |||
references(:project). | |||
where(Project.allowed_to_condition(args.shift || User.current, :view_documents, *args)) | |||
} | |||
@@ -83,7 +83,6 @@ class Group < Principal | |||
members.each do |member| | |||
MemberRole. | |||
joins(:member). | |||
references(:member). | |||
where("#{Member.table_name}.user_id = ? AND #{MemberRole.table_name}.inherited_from IN (?)", user.id, member.member_role_ids). | |||
each(&:destroy) | |||
end |
@@ -85,14 +85,12 @@ class Issue < ActiveRecord::Base | |||
scope :open, lambda {|*args| | |||
is_closed = args.size > 0 ? !args.first : false | |||
joins(:status). | |||
references(:status). | |||
where("#{IssueStatus.table_name}.is_closed = ?", is_closed) | |||
} | |||
scope :recently_updated, lambda { order("#{Issue.table_name}.updated_on DESC") } | |||
scope :on_active_project, lambda { | |||
joins(:project). | |||
references(:project). | |||
where("#{Project.table_name}.status = ?", Project::STATUS_ACTIVE) | |||
} | |||
scope :fixed_version, lambda {|versions| | |||
@@ -891,11 +889,9 @@ class Issue < ActiveRecord::Base | |||
issue_ids = issues.map(&:id) | |||
# Relations with issue_from in given issues and visible issue_to | |||
relations_from = IssueRelation.joins(:issue_to => :project). | |||
references(:issue_to => :project). | |||
where(visible_condition(user)).where(:issue_from_id => issue_ids).to_a | |||
# Relations with issue_to in given issues and visible issue_from | |||
relations_to = IssueRelation.joins(:issue_from => :project). | |||
references(:issue_from => :project). | |||
where(visible_condition(user)). | |||
where(:issue_to_id => issue_ids).to_a | |||
issues.each do |issue| | |||
@@ -1440,7 +1436,6 @@ class Issue < ActiveRecord::Base | |||
# Only need to update issues with a fixed_version from | |||
# a different project and that is not systemwide shared | |||
Issue.joins(:project, :fixed_version). | |||
references(:version, :fixed_version). | |||
where("#{Issue.table_name}.fixed_version_id IS NOT NULL" + | |||
" AND #{Issue.table_name}.project_id <> #{Version.table_name}.project_id" + | |||
" AND #{Version.table_name}.sharing <> 'system'"). |
@@ -46,7 +46,6 @@ class IssueQuery < Query | |||
user = args.shift || User.current | |||
base = Project.allowed_to_condition(user, :view_issues, *args) | |||
scope = joins("LEFT OUTER JOIN #{Project.table_name} ON #{table_name}.project_id = #{Project.table_name}.id"). | |||
references(:project). | |||
where("#{table_name}.project_id IS NULL OR (#{base})") | |||
if user.admin? |
@@ -46,7 +46,6 @@ class Journal < ActiveRecord::Base | |||
scope :visible, lambda {|*args| | |||
user = args.shift || User.current | |||
joins(:issue => :project). | |||
references(:project). | |||
where(Issue.visible_condition(user, *args)). | |||
where("(#{Journal.table_name}.private_notes = ? OR (#{Project.allowed_to_condition(user, :view_private_notes, *args)}))", false) | |||
} |
@@ -50,7 +50,6 @@ class Message < ActiveRecord::Base | |||
scope :visible, lambda {|*args| | |||
joins(:board => :project). | |||
references(:board => :project). | |||
where(Project.allowed_to_condition(args.shift || User.current, :view_messages, *args)) | |||
} | |||
@@ -39,7 +39,6 @@ class News < ActiveRecord::Base | |||
scope :visible, lambda {|*args| | |||
joins(:project). | |||
references([:author, :project]). | |||
where(Project.allowed_to_condition(args.shift || User.current, :view_news, *args)) | |||
} | |||
@@ -30,12 +30,10 @@ class Project < ActiveRecord::Base | |||
has_many :time_entry_activities | |||
has_many :members, | |||
lambda { joins(:principal, :roles). | |||
references(:principal, :roles). | |||
where("#{Principal.table_name}.type='User' AND #{Principal.table_name}.status=#{Principal::STATUS_ACTIVE}") } | |||
has_many :memberships, :class_name => 'Member' | |||
has_many :member_principals, | |||
lambda { joins(:principal). | |||
references(:principal). | |||
where("#{Principal.table_name}.status=#{Principal::STATUS_ACTIVE}")}, | |||
:class_name => 'Member' | |||
has_many :enabled_modules, :dependent => :delete_all | |||
@@ -438,7 +436,6 @@ class Project < ActiveRecord::Base | |||
@rolled_up_trackers ||= | |||
Tracker. | |||
joins(:projects). | |||
references(:project). | |||
joins("JOIN #{EnabledModule.table_name} ON #{EnabledModule.table_name}.project_id = #{Project.table_name}.id AND #{EnabledModule.table_name}.name = 'issue_tracking'"). | |||
select("DISTINCT #{Tracker.table_name}.*"). | |||
where("#{Project.table_name}.lft >= ? AND #{Project.table_name}.rgt <= ? AND #{Project.table_name}.status <> #{STATUS_ARCHIVED}", lft, rgt). | |||
@@ -462,7 +459,6 @@ class Project < ActiveRecord::Base | |||
@rolled_up_versions ||= | |||
Version. | |||
joins(:project). | |||
references(:project). | |||
where("#{Project.table_name}.lft >= ? AND #{Project.table_name}.rgt <= ? AND #{Project.table_name}.status <> ?", lft, rgt, STATUS_ARCHIVED) | |||
end | |||
@@ -471,7 +467,6 @@ class Project < ActiveRecord::Base | |||
if new_record? | |||
Version. | |||
joins(:project). | |||
references(:project). | |||
preload(:project). | |||
where("#{Project.table_name}.status <> ? AND #{Version.table_name}.sharing = 'system'", STATUS_ARCHIVED) | |||
else | |||
@@ -479,7 +474,6 @@ class Project < ActiveRecord::Base | |||
r = root? ? self : root | |||
Version. | |||
joins(:project). | |||
references(:project). | |||
preload(:project). | |||
where("#{Project.table_name}.id = #{id}" + | |||
" OR (#{Project.table_name}.status <> #{Project::STATUS_ARCHIVED} AND (" + |
@@ -46,17 +46,14 @@ class TimeEntry < ActiveRecord::Base | |||
scope :visible, lambda {|*args| | |||
joins(:project). | |||
references(:project). | |||
where(Project.allowed_to_condition(args.shift || User.current, :view_time_entries, *args)) | |||
} | |||
scope :on_issue, lambda {|issue| | |||
joins(:issue). | |||
references(:issue). | |||
where("#{Issue.table_name}.root_id = #{issue.root_id} AND #{Issue.table_name}.lft >= #{issue.lft} AND #{Issue.table_name}.rgt <= #{issue.rgt}") | |||
} | |||
scope :on_project, lambda {|project, include_subprojects| | |||
joins(:project). | |||
references(:project). | |||
where(project.project_condition(include_subprojects)) | |||
} | |||
scope :spent_between, lambda {|from, to| |
@@ -39,7 +39,6 @@ class Version < ActiveRecord::Base | |||
scope :open, lambda { where(:status => 'open') } | |||
scope :visible, lambda {|*args| | |||
joins(:project). | |||
references(:project). | |||
where(Project.allowed_to_condition(args.first || User.current, :view_issues)) | |||
} | |||
@@ -103,7 +103,7 @@ class QueryTest < ActiveSupport::TestCase | |||
def find_issues_with_query(query) | |||
Issue.joins(:status, :tracker, :project, :priority).where( | |||
query.statement | |||
).references([:assigned_to, :status, :tracker, :project, :priority]).to_a | |||
).to_a | |||
end | |||
def assert_find_issues_with_query_is_successful(query) |