aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorAaron Patterson <aaron.patterson@gmail.com>2010-12-25 16:36:07 -0700
committerAaron Patterson <aaron.patterson@gmail.com>2010-12-25 16:36:07 -0700
commit33b5a2637fbed8b2e5a10b84b79b32245edfb411 (patch)
tree6f1f85efc39ba10ac53cb7b101b6ee74d0049a9b
parent5b918bb97cb1801945ef778508a3738da98012c5 (diff)
downloadrails-33b5a2637fbed8b2e5a10b84b79b32245edfb411.tar.gz
rails-33b5a2637fbed8b2e5a10b84b79b32245edfb411.tar.bz2
rails-33b5a2637fbed8b2e5a10b84b79b32245edfb411.zip
refactoring method selection
-rw-r--r--activerecord/lib/active_record/association_preload.rb15
1 files changed, 5 insertions, 10 deletions
diff --git a/activerecord/lib/active_record/association_preload.rb b/activerecord/lib/active_record/association_preload.rb
index 7b4ff69b87..5feda5db0c 100644
--- a/activerecord/lib/active_record/association_preload.rb
+++ b/activerecord/lib/active_record/association_preload.rb
@@ -188,7 +188,6 @@ module ActiveRecord
left = reflection.klass.arel_table
- table_name = reflection.klass.quoted_table_name
id_to_record_map, ids = construct_id_map(records)
records.each {|record| record.send(reflection.name).loaded}
options = reflection.options
@@ -218,9 +217,7 @@ module ActiveRecord
custom_conditions = append_conditions(reflection, preload_options)
all_associated_records = associated_records(ids) do |some_ids|
- method = some_ids.length == 1 ? ['eq', some_ids.first] :
- ['in', some_ids]
-
+ method = in_or_equal(some_ids)
conditions = right[reflection.primary_key_name].send(*method)
conditions = custom_conditions.inject(conditions) do |ast, cond|
ast.and cond
@@ -364,7 +361,7 @@ module ActiveRecord
end
end
- method = ids.length == 1 ? ['eq', ids.first] : ['in', ids]
+ method = in_or_equal(ids)
conditions = table[primary_key].send(*method)
custom_conditions = append_conditions(reflection, preload_options)
@@ -403,9 +400,7 @@ module ActiveRecord
}
associated_records(ids) do |some_ids|
- method = some_ids.length == 1 ? ['eq', some_ids.first] :
- ['in', some_ids]
-
+ method = in_or_equal(some_ids)
where = conditions.inject(table[key].send(*method)) do |ast, cond|
ast.and cond
end
@@ -421,8 +416,8 @@ module ActiveRecord
].compact.map { |x| Arel.sql x }
end
- def in_or_equals_for_ids(ids)
- ids.size > 1 ? "IN (?)" : "= ?"
+ def in_or_equal(ids)
+ ids.length == 1 ? ['eq', ids.first] : ['in', ids]
end
# Some databases impose a limit on the number of ids in a list (in Oracle its 1000)