Skip to content
This repository
Browse code

store references as a string

  • Loading branch information...
commit a84a20e1cd2133932dd1bd33f862aa2605cc821e 1 parent f6cc665
Jon Leighton jonleighton authored
2  activerecord/lib/active_record/relation.rb
@@ -522,7 +522,7 @@ def references_eager_loaded_tables?
522 522 joined_tables = joined_tables.flatten.compact.map { |t| t.downcase }.uniq
523 523
524 524 (tables_in_string(to_sql) - joined_tables).any? ||
525   - (includes_values & references_values).any?
  525 + (references_values - joined_tables).any?
526 526 end
527 527
528 528 def tables_in_string(string)
2  activerecord/lib/active_record/relation/query_methods.rb
@@ -52,7 +52,7 @@ def references(*args)
52 52 return self if args.blank?
53 53
54 54 relation = clone
55   - relation.references_values = (references_values + args).flatten.uniq
  55 + relation.references_values = (references_values + args.flatten.map(&:to_s)).uniq
56 56 relation
57 57 end
58 58
4 activerecord/test/cases/relation_test.rb
@@ -140,13 +140,13 @@ def test_references_values
140 140 relation = Relation.new :a, :b
141 141 assert_equal [], relation.references_values
142 142 relation = relation.references(:foo).references(:omg, :lol)
143   - assert_equal [:foo, :omg, :lol], relation.references_values
  143 + assert_equal ['foo', 'omg', 'lol'], relation.references_values
144 144 end
145 145
146 146 def test_references_values_dont_duplicate
147 147 relation = Relation.new :a, :b
148 148 relation = relation.references(:foo).references(:foo)
149   - assert_equal [:foo], relation.references_values
  149 + assert_equal ['foo'], relation.references_values
150 150 end
151 151 end
152 152 end
8 activerecord/test/cases/relations_test.rb
@@ -1178,15 +1178,15 @@ def test_references_doesnt_trigger_eager_loading_if_reference_not_included
1178 1178
1179 1179 def test_automatically_added_references
1180 1180 scope = Post.where(:comments => { :body => "Bla" })
1181   - assert_equal [:comments], scope.references_values
  1181 + assert_equal ['comments'], scope.references_values
1182 1182
1183 1183 scope = Post.where('comments.body' => 'Bla')
1184   - assert_equal [:comments], scope.references_values
  1184 + assert_equal ['comments'], scope.references_values
1185 1185
1186 1186 scope = Post.having(:comments => { :body => "Bla" })
1187   - assert_equal [:comments], scope.references_values
  1187 + assert_equal ['comments'], scope.references_values
1188 1188
1189 1189 scope = Post.having('comments.body' => 'Bla')
1190   - assert_equal [:comments], scope.references_values
  1190 + assert_equal ['comments'], scope.references_values
1191 1191 end
1192 1192 end

0 comments on commit a84a20e

Please sign in to comment.
Something went wrong with that request. Please try again.