aboutsummaryrefslogtreecommitdiffstats
path: root/activerecord/test/cases/relations_test.rb
diff options
context:
space:
mode:
authorYves Senn <yves.senn@gmail.com>2014-01-21 17:17:13 +0100
committerYves Senn <yves.senn@gmail.com>2014-01-21 17:21:20 +0100
commite011258c30b61f30e40fb2d9b2f58eb1f700dfd5 (patch)
tree6244915c20c76047a61b08993ec8b0e3dd6590f4 /activerecord/test/cases/relations_test.rb
parentc60e06261b9e26110f8ac639224c153d4ff77752 (diff)
downloadrails-e011258c30b61f30e40fb2d9b2f58eb1f700dfd5.tar.gz
rails-e011258c30b61f30e40fb2d9b2f58eb1f700dfd5.tar.bz2
rails-e011258c30b61f30e40fb2d9b2f58eb1f700dfd5.zip
prepend table name for `Relation#select` columns.
This fixes a bug where `select(:id)` combined with `joins()` raised: ``` ActiveRecord::StatementInvalid: SQLite3::SQLException: ambiguous column name: id: SELECT id, authors.author_address_id FROM "posts" INNER JOIN "authors" ON "authors"."id" = "posts"."author_id" ORDER BY posts.id LIMIT 3 ``` The `select_values` are still String and Symbols because other parts (mainly calculations.rb) rely on that fact. /cc @tenderlove
Diffstat (limited to 'activerecord/test/cases/relations_test.rb')
-rw-r--r--activerecord/test/cases/relations_test.rb6
1 files changed, 6 insertions, 0 deletions
diff --git a/activerecord/test/cases/relations_test.rb b/activerecord/test/cases/relations_test.rb
index 9227c2b72f..e874c93110 100644
--- a/activerecord/test/cases/relations_test.rb
+++ b/activerecord/test/cases/relations_test.rb
@@ -1505,6 +1505,12 @@ class RelationTest < ActiveRecord::TestCase
end
end
+ test "joins with select" do
+ posts = Post.joins(:author).select("id", "authors.author_address_id").order("posts.id").limit(3)
+ assert_equal [1, 2, 4], posts.map(&:id)
+ assert_equal [1, 1, 1], posts.map(&:author_address_id)
+ end
+
test "delegations do not leak to other classes" do
Topic.all.by_lifo
assert Topic.all.class.method_defined?(:by_lifo)