Skip to content
Browse files

Fix bug in collection_singular_ids on has many through association wi…

…th conditions and includes,

when condtions references tables from includes.
Test fail because of invalid sql:
ActiveRecord::StatementInvalid: SQLite3::SQLException: no such column: comments.id:
SELECT "posts".id FROM "posts" INNER JOIN "readers" ON "posts"."id" = "readers"."post_id"
WHERE "readers"."person_id" = 1 AND (comments.id is null)

Bug described in github#925

This commit will revert fix from 3436fdf , but tests is ok.

Bug described in #6569 ticket.
  • Loading branch information...
1 parent c713cf9 commit 66dd2d3d10edd501c33a6aead035691a6a54f6c7 @lysenko lysenko committed Mar 27, 2011
View
2 activerecord/lib/active_record/associations/collection_association.rb
@@ -50,7 +50,7 @@ def ids_reader
else
column = "#{reflection.quoted_table_name}.#{reflection.association_primary_key}"
- scoped.select(column).except(:includes).map! do |record|
+ scoped.select(column).map! do |record|
record.send(reflection.association_primary_key)
end
end
View
5 activerecord/test/cases/associations/has_many_through_associations_test.rb
@@ -714,6 +714,11 @@ def test_get_has_many_through_belongs_to_ids_with_conditions
assert_equal [categories(:general).id], authors(:mary).categories_like_general_ids
end
+ def test_get_collection_singular_ids_on_has_many_through_with_conditions_and_include
+ person = Person.first
+ assert_equal person.posts_with_no_comment_ids, person.posts_with_no_comments.map(&:id)
+ end
+
def test_count_has_many_through_with_named_scope
assert_equal 2, authors(:mary).categories.count
assert_equal 1, authors(:mary).categories.general.count

0 comments on commit 66dd2d3

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