Permalink
Browse files

Revert "Optimize <association>_ids for hm:t with belongs_to source". …

…The optimisation has too many edge cases, such as when the reflection, source reflection, or through reflection has conditions, orders, etc. [#6153 state:resolved]

This reverts commit 373b053.

Conflicts:

	activerecord/lib/active_record/associations.rb
  • Loading branch information...
1 parent 4e13625 commit 1619c2435b2b9c821b2b0dcab9624dbb6b23eaaa @jonleighton jonleighton committed with tenderlove Dec 22, 2010
@@ -1512,16 +1512,9 @@ def collection_reader_method(reflection, association_proxy_class)
if send(reflection.name).loaded? || reflection.options[:finder_sql]
send(reflection.name).map { |r| r.id }
else
- if reflection.through_reflection && reflection.source_reflection.belongs_to?
- through = reflection.through_reflection
- primary_key = reflection.source_reflection.primary_key_name
- send(through.name).select("DISTINCT #{through.quoted_table_name}.#{primary_key}").map! { |r| r.send(primary_key) }
- else
- send(reflection.name).select("#{reflection.quoted_table_name}.#{reflection.klass.primary_key}").except(:includes).map! { |r| r.id }
- end
+ send(reflection.name).select("#{reflection.quoted_table_name}.#{reflection.klass.primary_key}").except(:includes).map! { |r| r.id }
end
end
-
end
def collection_accessor_methods(reflection, association_proxy_class, writer = true)
@@ -334,12 +334,8 @@ def test_inner_join_with_quoted_table_name
assert_equal 2, people(:michael).jobs.size
end
- def test_get_ids_for_belongs_to_source
- assert_sql(/DISTINCT/) { assert_equal [posts(:welcome).id, posts(:authorless).id].sort, people(:michael).post_ids.sort }
- end
-
- def test_get_ids_for_has_many_source
- assert_equal [comments(:eager_other_comment1).id], authors(:mary).comment_ids
+ def test_get_ids
+ assert_equal [posts(:welcome).id, posts(:authorless).id].sort, people(:michael).post_ids.sort
end
def test_get_ids_for_loaded_associations

0 comments on commit 1619c24

Please sign in to comment.