diff options
author | Vipul A M <vipulnsward@gmail.com> | 2013-07-06 19:51:15 +0530 |
---|---|---|
committer | Vipul A M <vipulnsward@gmail.com> | 2013-07-06 20:44:53 +0530 |
commit | e7e28a71be68271c7892477c1b9336316a1871bc (patch) | |
tree | 2c5152533bf5f5de5f91d7c7ba816ea75dbc4024 /activerecord/lib/active_record | |
parent | 01d4941d0c87764742562c59d4bf7bb34ac108c4 (diff) | |
download | rails-e7e28a71be68271c7892477c1b9336316a1871bc.tar.gz rails-e7e28a71be68271c7892477c1b9336316a1871bc.tar.bz2 rails-e7e28a71be68271c7892477c1b9336316a1871bc.zip |
Extract common query to a constant.
Perf ref: https://gist.github.com/vipulnsward/8209749201dfdd678c97
Diffstat (limited to 'activerecord/lib/active_record')
-rw-r--r-- | activerecord/lib/active_record/relation/finder_methods.rb | 4 |
1 files changed, 3 insertions, 1 deletions
diff --git a/activerecord/lib/active_record/relation/finder_methods.rb b/activerecord/lib/active_record/relation/finder_methods.rb index bad5886cde..9186b33bd2 100644 --- a/activerecord/lib/active_record/relation/finder_methods.rb +++ b/activerecord/lib/active_record/relation/finder_methods.rb @@ -1,5 +1,7 @@ module ActiveRecord module FinderMethods + ONE_AS_ONE = '1 AS one' + # Find by id - This can either be a specific id (1), a list of ids (1, 5, 6), or an array of ids ([5, 6, 10]). # If no record can be found for all of the listed ids, then RecordNotFound will be raised. If the primary key # is an integer, find by id coerces its arguments using +to_i+. @@ -202,7 +204,7 @@ module ActiveRecord relation = construct_relation_for_association_find(construct_join_dependency) return false if ActiveRecord::NullRelation === relation - relation = relation.except(:select, :order).select("1 AS one").limit(1) + relation = relation.except(:select, :order).select(ONE_AS_ONE).limit(1) case conditions when Array, Hash |