From 93f19071ad9d337a9f6f2fc9278c33e05597951d Mon Sep 17 00:00:00 2001 From: Gannon McGibbon Date: Wed, 5 Dec 2018 10:52:17 -0500 Subject: [PATCH] Fix join table column quoting with SQLite. --- activerecord/CHANGELOG.md | 4 ++++ .../lib/active_record/connection_adapters/sqlite3/quoting.rb | 4 ++++ activerecord/test/cases/calculations_test.rb | 4 ++++ 3 files changed, 12 insertions(+) diff --git a/activerecord/CHANGELOG.md b/activerecord/CHANGELOG.md index 587831f1bb..6f2b49c428 100644 --- a/activerecord/CHANGELOG.md +++ b/activerecord/CHANGELOG.md @@ -1,3 +1,7 @@ +* Fix join table column quoting with SQLite. + + *Gannon McGibbon* + * Allow disabling scopes generated by `ActiveRecord.enum`. *Alfred Dominic* diff --git a/activerecord/lib/active_record/connection_adapters/sqlite3/quoting.rb b/activerecord/lib/active_record/connection_adapters/sqlite3/quoting.rb index b2dcdb5373..29f0e19a98 100644 --- a/activerecord/lib/active_record/connection_adapters/sqlite3/quoting.rb +++ b/activerecord/lib/active_record/connection_adapters/sqlite3/quoting.rb @@ -12,6 +12,10 @@ module ActiveRecord quote_column_name(attr) end + def quote_table_name(name) + @quoted_table_names[name] ||= super.gsub(".", "\".\"").freeze + end + def quote_column_name(name) @quoted_column_names[name] ||= %Q("#{super.gsub('"', '""')}") end diff --git a/activerecord/test/cases/calculations_test.rb b/activerecord/test/cases/calculations_test.rb index 4cb0dc66ed..4d3db912c5 100644 --- a/activerecord/test/cases/calculations_test.rb +++ b/activerecord/test/cases/calculations_test.rb @@ -721,6 +721,10 @@ class CalculationsTest < ActiveRecord::TestCase assert_equal [], Topic.includes(:replies).order(:id).offset(5).pluck(:id) end + def test_pluck_with_join + assert_equal [[2, 2], [4, 4]], Reply.includes(:topic).pluck(:id, :"topics.id") + end + def test_group_by_with_limit expected = { "Post" => 8, "SpecialPost" => 1 } actual = Post.includes(:comments).group(:type).order(:type).limit(2).count("comments.id")