Rewrites named scopes with ARel queries.
git-svn-id: svn+ssh://rubyforge.org/var/svn/redmine/trunk@10950 e93f8b46-1217-0410-a6f0-8f06a7374b81
This commit is contained in:
1 parent
4896d5c7e8
commit
7222e4012d
12 files changed
+55
-55
No files matched your search
+13
-16
@@ -42,27 +42,24 @@ class TimeEntry < ActiveRecord::Base
|
||||
before_validation :set_project_if_nil
|
||||
validate :validate_time_entry
|
||||
|
||||
scope :visible, lambda {|*args| {
|
||||
:include => :project,
|
||||
:conditions => Project.allowed_to_condition(args.shift || User.current, :view_time_entries, *args)
|
||||
}}
|
||||
scope :on_issue, lambda {|issue| {
|
||||
:include => :issue,
|
||||
:conditions => "#{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| {
|
||||
:include => :project,
|
||||
:conditions => project.project_condition(include_subprojects)
|
||||
}}
|
||||
scope :visible, lambda {|*args|
|
||||
includes(:project).where(Project.allowed_to_condition(args.shift || User.current, :view_time_entries, *args))
|
||||
}
|
||||
scope :on_issue, lambda {|issue|
|
||||
includes(: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|
|
||||
includes(:project).where(project.project_condition(include_subprojects))
|
||||
}
|
||||
scope :spent_between, lambda {|from, to|
|
||||
if from && to
|
||||
{:conditions => ["#{TimeEntry.table_name}.spent_on BETWEEN ? AND ?", from, to]}
|
||||
where("#{TimeEntry.table_name}.spent_on BETWEEN ? AND ?", from, to)
|
||||
elsif from
|
||||
{:conditions => ["#{TimeEntry.table_name}.spent_on >= ?", from]}
|
||||
where("#{TimeEntry.table_name}.spent_on >= ?", from)
|
||||
elsif to
|
||||
{:conditions => ["#{TimeEntry.table_name}.spent_on <= ?", to]}
|
||||
where("#{TimeEntry.table_name}.spent_on <= ?", to)
|
||||
else
|
||||
{}
|
||||
where(nil)
|
||||
end
|
||||
}
|
||||
|
||||
|
||||
Reference in new issue
Block a user