Order scopes cleanup.

git-svn-id: http://svn.redmine.org/redmine/trunk@13526 e93f8b46-1217-0410-a6f0-8f06a7374b81
This commit is contained in:
Jean-Philippe Lang
2014-10-29 21:49:33 +00:00
parent 47e74dc689
commit 522bebe5ed
6 changed files with 7 additions and 7 deletions

View File

@@ -42,7 +42,7 @@ class CustomField < ActiveRecord::Base
end end
end end
scope :sorted, lambda { order("#{table_name}.position ASC") } scope :sorted, lambda { order(:position) }
scope :visible, lambda {|*args| scope :visible, lambda {|*args|
user = args.shift || User.current user = args.shift || User.current
if user.admin? if user.admin?

View File

@@ -36,7 +36,7 @@ class Enumeration < ActiveRecord::Base
validates_length_of :name, :maximum => 30 validates_length_of :name, :maximum => 30
scope :shared, lambda { where(:project_id => nil) } scope :shared, lambda { where(:project_id => nil) }
scope :sorted, lambda { order("#{table_name}.position ASC") } scope :sorted, lambda { order(:position) }
scope :active, lambda { where(:active => true) } scope :active, lambda { where(:active => true) }
scope :system, lambda { where(:project_id => nil) } scope :system, lambda { where(:project_id => nil) }
scope :named, lambda {|arg| where("LOWER(#{table_name}.name) = LOWER(?)", arg.to_s.strip)} scope :named, lambda {|arg| where("LOWER(#{table_name}.name) = LOWER(?)", arg.to_s.strip)}

View File

@@ -32,7 +32,7 @@ class Group < Principal
before_destroy :remove_references_before_destroy before_destroy :remove_references_before_destroy
scope :sorted, lambda { order("#{table_name}.type, #{table_name}.lastname ASC") } scope :sorted, lambda { order(:type => :asc, :lastname => :desc) }
scope :named, lambda {|arg| where("LOWER(#{table_name}.lastname) = LOWER(?)", arg.to_s.strip)} scope :named, lambda {|arg| where("LOWER(#{table_name}.lastname) = LOWER(?)", arg.to_s.strip)}
scope :givable, lambda {where(:type => 'Group')} scope :givable, lambda {where(:type => 'Group')}

View File

@@ -30,7 +30,7 @@ class IssueStatus < ActiveRecord::Base
validates_inclusion_of :default_done_ratio, :in => 0..100, :allow_nil => true validates_inclusion_of :default_done_ratio, :in => 0..100, :allow_nil => true
attr_protected :id attr_protected :id
scope :sorted, lambda { order("#{table_name}.position ASC") } scope :sorted, lambda { order(:position) }
scope :named, lambda {|arg| where("LOWER(#{table_name}.name) = LOWER(?)", arg.to_s.strip)} scope :named, lambda {|arg| where("LOWER(#{table_name}.name) = LOWER(?)", arg.to_s.strip)}
def update_default def update_default

View File

@@ -39,8 +39,8 @@ class Role < ActiveRecord::Base
['own', :label_issues_visibility_own] ['own', :label_issues_visibility_own]
] ]
scope :sorted, lambda { order("#{table_name}.builtin ASC, #{table_name}.position ASC") } scope :sorted, lambda { order(:builtin, :position) }
scope :givable, lambda { order("#{table_name}.position ASC").where(:builtin => 0) } scope :givable, lambda { order(:position).where(:builtin => 0) }
scope :builtin, lambda { |*args| scope :builtin, lambda { |*args|
compare = (args.first == true ? 'not' : '') compare = (args.first == true ? 'not' : '')
where("#{compare} builtin = 0") where("#{compare} builtin = 0")

View File

@@ -41,7 +41,7 @@ class Tracker < ActiveRecord::Base
validates_uniqueness_of :name validates_uniqueness_of :name
validates_length_of :name, :maximum => 30 validates_length_of :name, :maximum => 30
scope :sorted, lambda { order("#{table_name}.position ASC") } scope :sorted, lambda { order(:position) }
scope :named, lambda {|arg| where("LOWER(#{table_name}.name) = LOWER(?)", arg.to_s.strip)} scope :named, lambda {|arg| where("LOWER(#{table_name}.name) = LOWER(?)", arg.to_s.strip)}
def to_s; name end def to_s; name end