Skip to content
This repository was archived by the owner on Mar 30, 2022. It is now read-only.

Commit 9681537

Browse files
committed
Fixed missing bind values when using #in with scope that joins polymorphic association
1 parent 5542266 commit 9681537

File tree

2 files changed

+8
-1
lines changed

2 files changed

+8
-1
lines changed

lib/squeel/adapters/active_record/4.1/relation_extensions.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -197,7 +197,7 @@ def build_where(opts, other = [])
197197
preprocess_attrs_with_ar(attributes)
198198
when Squeel::Nodes::Node
199199
arg.grep(::ActiveRecord::Relation) do |rel|
200-
self.bind_values += rel.bind_values
200+
self.bind_values += rel.arel.bind_values + rel.bind_values
201201
end
202202
arg
203203
else

spec/squeel/adapters/active_record/relation_extensions_spec.rb

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -632,6 +632,13 @@ module ActiveRecord
632632
articles.should have(3).articles
633633
end
634634

635+
it 'allows a subquery from Relation that in a Squeel node' do
636+
names = [Person.first.name, Person.last.name]
637+
scope = Person.where(name: names).joins(:notes).select { notes.notable_id }
638+
people = Person.where { id.in scope }
639+
people.should eq([Person.first, Person.last])
640+
end
641+
635642
it 'is backwards-compatible with "where.not"' do
636643
if activerecord_version_at_least '4.0.0'
637644
name = Person.first.name

0 commit comments

Comments
 (0)