diff options
author | Daniel Colson <danieljamescolson@gmail.com> | 2018-03-11 15:09:25 -0400 |
---|---|---|
committer | Daniel Colson <danieljamescolson@gmail.com> | 2018-03-11 18:10:49 -0400 |
commit | da3492fdba8542db4e0541d37d9dc8b1e4064787 (patch) | |
tree | 64145685410c7cb15dacbed21841c0b626b382a4 /activerecord/lib | |
parent | 58eda3cfd8b670718ba9b99bdbe137c4320ec32f (diff) | |
download | rails-da3492fdba8542db4e0541d37d9dc8b1e4064787.tar.gz rails-da3492fdba8542db4e0541d37d9dc8b1e4064787.tar.bz2 rails-da3492fdba8542db4e0541d37d9dc8b1e4064787.zip |
Use PredicateBuilder for bind params in Batches
Using the PredicateBuilder to build the bind
attributes allows Batch to drop its dependency on
Relation::QueryAttribute and Arel::Nodes::BindParam
Diffstat (limited to 'activerecord/lib')
-rw-r--r-- | activerecord/lib/active_record/relation/batches.rb | 26 |
1 files changed, 16 insertions, 10 deletions
diff --git a/activerecord/lib/active_record/relation/batches.rb b/activerecord/lib/active_record/relation/batches.rb index 561869017a..ec4bb06c57 100644 --- a/activerecord/lib/active_record/relation/batches.rb +++ b/activerecord/lib/active_record/relation/batches.rb @@ -251,25 +251,31 @@ module ActiveRecord end end - attr = Relation::QueryAttribute.new(primary_key, primary_key_offset, klass.type_for_attribute(primary_key)) - batch_relation = relation.where(arel_attribute(primary_key).gt(Arel::Nodes::BindParam.new(attr))) + bind = primary_key_bind(primary_key_offset) + batch_relation = relation.where(arel_attribute(primary_key).gt(bind)) end end private def apply_limits(relation, start, finish) - if start - attr = Relation::QueryAttribute.new(primary_key, start, klass.type_for_attribute(primary_key)) - relation = relation.where(arel_attribute(primary_key).gteq(Arel::Nodes::BindParam.new(attr))) - end - if finish - attr = Relation::QueryAttribute.new(primary_key, finish, klass.type_for_attribute(primary_key)) - relation = relation.where(arel_attribute(primary_key).lteq(Arel::Nodes::BindParam.new(attr))) - end + relation = apply_start_limit(relation, start) if start + relation = apply_finish_limit(relation, finish) if finish relation end + def apply_start_limit(relation, start) + relation.where(arel_attribute(primary_key).gteq(primary_key_bind(start))) + end + + def apply_finish_limit(relation, finish) + relation.where(arel_attribute(primary_key).lteq(primary_key_bind(finish))) + end + + def primary_key_bind(value) + predicate_builder.build_bind_attribute(primary_key, value) + end + def batch_order arel_attribute(primary_key).asc end |