Permalink
Browse files

include bind values from the default scope

  • Loading branch information...
1 parent 677b64f commit 2eecc0d8dccf7f12518e05a72192eb853e5ee474 @tenderlove tenderlove committed May 17, 2013
Showing with 5 additions and 6 deletions.
  1. +4 −2 activerecord/lib/active_record/relation.rb
  2. +1 −4 activerecord/test/cases/relation_test.rb
@@ -489,11 +489,13 @@ def to_sql
# User.where(name: 'Oscar').where_values_hash
# # => {name: "Oscar"}
def where_values_hash
- equalities = with_default_scope.where_values.grep(Arel::Nodes::Equality).find_all { |node|
+ scope = with_default_scope
+ equalities = scope.where_values.grep(Arel::Nodes::Equality).find_all { |node|
node.left.relation.name == table_name
}
- binds = Hash[bind_values.find_all(&:first).map { |column, v| [column.name, v] }]
+ binds = Hash[scope.bind_values.find_all(&:first).map { |column, v| [column.name, v] }]
+ binds.merge!(Hash[bind_values.find_all(&:first).map { |column, v| [column.name, v] }])
Hash[equalities.map { |where|
name = where.left.name
@@ -12,10 +12,7 @@ class FakeKlass < Struct.new(:table_name, :name)
end
def test_construction
- relation = nil
- assert_nothing_raised do
- relation = Relation.new FakeKlass, :b
- end
+ relation = Relation.new FakeKlass, :b
assert_equal FakeKlass, relation.klass
assert_equal :b, relation.table
assert !relation.loaded, 'relation is not loaded'

0 comments on commit 2eecc0d

Please sign in to comment.