aboutsummaryrefslogtreecommitdiffstats
path: root/activerecord/test/cases/relations_test.rb
diff options
context:
space:
mode:
authorRyuta Kamizono <kamipo@gmail.com>2019-02-13 02:06:06 +0900
committerRyuta Kamizono <kamipo@gmail.com>2019-02-13 02:47:46 +0900
commit0ee96d13de29680e148ccb8e5b68025f29fd091c (patch)
treee8e2095bc74f34b8a0447cace738368e8ff79bef /activerecord/test/cases/relations_test.rb
parented9acb4fcc793ce1ab68a0e5076dc9458cc7f218 (diff)
downloadrails-0ee96d13de29680e148ccb8e5b68025f29fd091c.tar.gz
rails-0ee96d13de29680e148ccb8e5b68025f29fd091c.tar.bz2
rails-0ee96d13de29680e148ccb8e5b68025f29fd091c.zip
Fix `pluck` and `select` with custom attributes
Currently custom attributes are always qualified by the table name in the generated SQL wrongly even if the table doesn't have the named column, it would cause an invalid SQL error. Custom attributes should only be qualified if the table has the same named column.
Diffstat (limited to 'activerecord/test/cases/relations_test.rb')
-rw-r--r--activerecord/test/cases/relations_test.rb7
1 files changed, 7 insertions, 0 deletions
diff --git a/activerecord/test/cases/relations_test.rb b/activerecord/test/cases/relations_test.rb
index 0ab0459c38..857d743605 100644
--- a/activerecord/test/cases/relations_test.rb
+++ b/activerecord/test/cases/relations_test.rb
@@ -14,6 +14,7 @@ require "models/person"
require "models/computer"
require "models/reply"
require "models/company"
+require "models/contract"
require "models/bird"
require "models/car"
require "models/engine"
@@ -1815,6 +1816,12 @@ class RelationTest < ActiveRecord::TestCase
assert_equal [1, 1, 1], posts.map(&:author_address_id)
end
+ test "joins with select custom attribute" do
+ contract = Company.create!(name: "test").contracts.create!
+ company = Company.joins(:contracts).select(:id, :metadata).find(contract.company_id)
+ assert_equal contract.metadata, company.metadata
+ end
+
test "delegations do not leak to other classes" do
Topic.all.by_lifo
assert Topic.all.class.method_defined?(:by_lifo)