rails/rails — pull request #12588 by pftg (2013-10-18 20:31:13+00:00)
Title: Inline bind values for sub-queries generated for Relation in where

Generated sub-query for Relation as array condition for `where` method
did not take in account bind values of the Relation.
Fixed by inlining bind values into the sub-query.

There is another solution, but it's more complicated, to pass bind values like: https://github.com/rails/rails/blob/master/activerecord/lib/active_record/relation/query_methods.rb#L902

```ruby
opts = PredicateBuilder.resolve_column_aliases(klass, opts)
attributes = @klass.send(:expand_hash_conditions_for_aggregates, opts)

attributes.values.grep(ActiveRecord::Relation) do |rel|
self.bind_values += rel.bind_values
end

PredicateBuilder.build_from_hash(klass, attributes, table)
```

Closes: #12586