diff options
author | Jean-Philippe Lang <jp_lang@yahoo.fr> | 2012-12-07 17:59:20 +0000 |
---|---|---|
committer | Jean-Philippe Lang <jp_lang@yahoo.fr> | 2012-12-07 17:59:20 +0000 |
commit | 7222e4012db58c53d364e3b065e70338c094e878 (patch) | |
tree | 2d0a723b9d9030591967b9932587fb5987062ce0 /app/models/time_entry.rb | |
parent | 4896d5c7e83bb3cc7996c5ab09441c90e7cd9ce1 (diff) | |
download | redmine-7222e4012db58c53d364e3b065e70338c094e878.tar.gz redmine-7222e4012db58c53d364e3b065e70338c094e878.zip |
Rewrites named scopes with ARel queries.
git-svn-id: svn+ssh://rubyforge.org/var/svn/redmine/trunk@10950 e93f8b46-1217-0410-a6f0-8f06a7374b81
Diffstat (limited to 'app/models/time_entry.rb')
-rw-r--r-- | app/models/time_entry.rb | 29 |
1 files changed, 13 insertions, 16 deletions
diff --git a/app/models/time_entry.rb b/app/models/time_entry.rb index ef085d875..3abe114c0 100644 --- a/app/models/time_entry.rb +++ b/app/models/time_entry.rb @@ -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 } |