diff options
author | Sean Griffin <sean@thoughtbot.com> | 2015-01-27 09:15:22 -0700 |
---|---|---|
committer | Sean Griffin <sean@thoughtbot.com> | 2015-01-27 09:18:30 -0700 |
commit | 16ce2eecd3eb23034555bb37b29c12985243d908 (patch) | |
tree | bfced5ffbc70aef244ff5a57c0d060028b9e7f4f /activerecord/lib/active_record/relation.rb | |
parent | ad20b41cb941ac4271b58e083edba57cc6233b82 (diff) | |
download | rails-16ce2eecd3eb23034555bb37b29c12985243d908.tar.gz rails-16ce2eecd3eb23034555bb37b29c12985243d908.tar.bz2 rails-16ce2eecd3eb23034555bb37b29c12985243d908.zip |
Unify access to bind values on Relation
The bind values can come from four places. `having`, `where`, `joins`,
and `from` when selecting from a subquery that contains binds. These
need to be kept in a specific order, since the clauses will always
appear in that order. Up until recently, they were not.
Additionally, `joins` actually did keep its bind values in a separate
location (presumably because it's the only case that people noticed was
broken). However, this meant that anything accessing just `bind_values`
was broken (which most places were). This is no longer possible, there
is only a single way to access the bind values, and it includes joins in
the proper location. The setter was removed yesterday, so breaking `+=`
cases is not possible.
I'm still not happy that `joins` is putting it's bind values on the
Arel AST, and I'm planning on refactoring it further, but this removes a
ton of bug cases.
Diffstat (limited to 'activerecord/lib/active_record/relation.rb')
-rw-r--r-- | activerecord/lib/active_record/relation.rb | 10 |
1 files changed, 4 insertions, 6 deletions
diff --git a/activerecord/lib/active_record/relation.rb b/activerecord/lib/active_record/relation.rb index a9b43ac816..07e27fe59e 100644 --- a/activerecord/lib/active_record/relation.rb +++ b/activerecord/lib/active_record/relation.rb @@ -342,8 +342,7 @@ module ActiveRecord stmt.wheres = arel.constraints end - bvs = arel.bind_values + bind_values - @klass.connection.update stmt, 'SQL', bvs + @klass.connection.update stmt, 'SQL', bind_values end # Updates an object (or multiple objects) and saves it to the database, if validations pass. @@ -559,11 +558,10 @@ module ActiveRecord find_with_associations { |rel| relation = rel } end - arel = relation.arel - binds = arel.bind_values + relation.bind_values + binds = relation.bind_values binds = connection.prepare_binds_for_database(binds) binds.map! { |_, value| connection.quote(value) } - collect = visitor.accept(arel.ast, Arel::Collectors::Bind.new) + collect = visitor.accept(relation.arel.ast, Arel::Collectors::Bind.new) collect.substitute_binds(binds).join end end @@ -636,7 +634,7 @@ module ActiveRecord private def exec_queries - @records = eager_loading? ? find_with_associations : @klass.find_by_sql(arel, arel.bind_values + bind_values) + @records = eager_loading? ? find_with_associations : @klass.find_by_sql(arel, bind_values) preload = preload_values preload += includes_values unless eager_loading? |