diff --git a/lib/squeel/adapters/active_record/4.1/relation_extensions.rb b/lib/squeel/adapters/active_record/4.1/relation_extensions.rb index 38e9335..8129af1 100644 --- a/lib/squeel/adapters/active_record/4.1/relation_extensions.rb +++ b/lib/squeel/adapters/active_record/4.1/relation_extensions.rb @@ -197,7 +197,7 @@ def build_where(opts, other = []) preprocess_attrs_with_ar(attributes) when Squeel::Nodes::Node arg.grep(::ActiveRecord::Relation) do |rel| - self.bind_values += rel.bind_values + self.bind_values += rel.arel.bind_values + rel.bind_values end arg else diff --git a/spec/squeel/adapters/active_record/relation_extensions_spec.rb b/spec/squeel/adapters/active_record/relation_extensions_spec.rb index 0ea9667..70a75ab 100644 --- a/spec/squeel/adapters/active_record/relation_extensions_spec.rb +++ b/spec/squeel/adapters/active_record/relation_extensions_spec.rb @@ -632,6 +632,13 @@ module ActiveRecord articles.should have(3).articles end + it 'allows a subquery from Relation that in a Squeel node' do + names = [Person.first.name, Person.last.name] + scope = Person.where(name: names).joins(:notes).select { notes.notable_id } + people = Person.where { id.in scope } + people.should eq([Person.first, Person.last]) + end + it 'is backwards-compatible with "where.not"' do if activerecord_version_at_least '4.0.0' name = Person.first.name