Navigation Menu

Skip to content

Instantly share code, notes, and snippets.

@AquaGeek
Created May 14, 2011 02:35
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save AquaGeek/971814 to your computer and use it in GitHub Desktop.
Save AquaGeek/971814 to your computer and use it in GitHub Desktop.
Rails Lighthouse ticket #6569
From e06b00e29126a0823322a74233a026dc29837273 Mon Sep 17 00:00:00 2001
From: Anatoliy Lysenko <a.o.lysenko@gmail.com>
Date: Sun, 27 Mar 2011 16:40:37 +0300
Subject: [PATCH] Added test for get has many through singular ids with conditions and include.
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 #6569 ticket.
---
.../has_many_through_associations_test.rb | 5 +++++
1 files changed, 5 insertions(+), 0 deletions(-)
diff --git a/activerecord/test/cases/associations/has_many_through_associations_test.rb b/activerecord/test/cases/associations/has_many_through_associations_test.rb
index 1efe342..e9bb5a8 100644
--- a/activerecord/test/cases/associations/has_many_through_associations_test.rb
+++ b/activerecord/test/cases/associations/has_many_through_associations_test.rb
@@ -714,6 +714,11 @@ class HasManyThroughAssociationsTest < ActiveRecord::TestCase
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
--
1.7.0.4
From d2fda3dbfdee09a6152c909f51c3f54da137a49e Mon Sep 17 00:00:00 2001
From: Anatoliy Lysenko <a.o.lysenko@gmail.com>
Date: Sun, 3 Apr 2011 14:38:47 +0300
Subject: [PATCH 2/2] Fix bug in collection_singular_ids on has many through association with conditions and includes,
when condtions references tables from includes.
This commit will revert fix from https://github.com/rails/rails/commit/3436fdfc12d58925e3d981e0afa61084ea34736c , but tests is ok.
---
.../associations/collection_association.rb | 2 +-
1 files changed, 1 insertions(+), 1 deletions(-)
diff --git a/activerecord/lib/active_record/associations/collection_association.rb b/activerecord/lib/active_record/associations/collection_association.rb
index 9f4fc44..80f0537 100644
--- a/activerecord/lib/active_record/associations/collection_association.rb
+++ b/activerecord/lib/active_record/associations/collection_association.rb
@@ -57,7 +57,7 @@ module ActiveRecord
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
--
1.7.0.4
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment