@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).
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
scope :visible, lambda {|*args|
joins(:project).
- references(:project).
where(Project.allowed_to_condition(args.shift || User.current, :view_messages, *args))
}
scope :visible, lambda {|*args|
joins(:repository => :project).
- references(:repository => :project).
where(Project.allowed_to_condition(args.shift || User.current, :view_changesets, *args))
}
scope :visible, lambda {|*args|
joins(:project).
- references(:project).
where(Project.allowed_to_condition(args.shift || User.current, :view_documents, *args))
}
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
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|
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|
# 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'").
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?
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)
}
scope :visible, lambda {|*args|
joins(:board => :project).
- references(:board => :project).
where(Project.allowed_to_condition(args.shift || User.current, :view_messages, *args))
}
scope :visible, lambda {|*args|
joins(:project).
- references([:author, :project]).
where(Project.allowed_to_condition(args.shift || User.current, :view_news, *args))
}
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
@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).
@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
if new_record?
Version.
joins(:project).
- references(:project).
preload(:project).
where("#{Project.table_name}.status <> ? AND #{Version.table_name}.sharing = 'system'", STATUS_ARCHIVED)
else
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 (" +
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|
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))
}
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)