Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Detect join nodes properly in AR Contexts.

Fixes #273
  • Loading branch information...
commit b14aaa348371d00189b28c343506cc2d7a9ce0c1 1 parent eaa0033
@ernie ernie authored
View
5 CHANGELOG.md
@@ -1,3 +1,8 @@
+## 1.1.2 (unreleased)
+
+* Properly append binds from a relation used in a subquery. Fixes #272.
+* Use the correct attribute name when finding a Join node. Fixes #273.
+
## 1.1.1 (2013-09-03)
* Update relation extensions to support new count behavior in Active Record
View
2  lib/squeel/adapters/active_record/context.rb
@@ -23,7 +23,7 @@ def find(object, parent = @base)
}
when Nodes::Join
@object.join_associations.detect { |j|
- j.reflection.name == object.name && j.parent == parent &&
+ j.reflection.name == object._name && j.parent == parent &&
(object.polymorphic? ? j.reflection.klass == object._klass : true)
}
else
View
6 spec/squeel/adapters/active_record/relation_extensions_spec.rb
@@ -496,6 +496,12 @@ module ActiveRecord
people_and_article_notes.should have(40).items
end
+ it 'maps conditions onto their proper table with a polymorphic belongs_to join followed by a polymorphic has_many join' do
+ relation = Note.joins{notable(Article).notes}.
+ where{notable(Article).notes.note.eq('zomg')}
+ relation.to_sql.should match /"notes_articles"\."note" = 'zomg'/
+ end
+
it 'allows a subquery on the value side of a predicate' do
names = [Person.first.name, Person.last.name]
old_and_busted = Person.where(:name => names)
View
2  spec/support/models.rb
@@ -71,7 +71,7 @@ class Article < ActiveRecord::Base
belongs_to :person
has_many :comments
has_and_belongs_to_many :tags
- has_many :notes, :as => :notable
+ has_many :notes, :as => :notable
has_many :commenters, :through => :comments, :source => :person
has_many :uniq_commenters, :through => :comments, :source => :person, :uniq => true
end
Please sign in to comment.
Something went wrong with that request. Please try again.