1
0
Fork 0
mirror of https://github.com/rails/rails.git synced 2022-11-09 12:12:34 -05:00

Reload schema after ignored_columns reassignment

reload column_names after ignored_columns assignment

code review: remove unnecessary setup and move up reload_schema_from_cache
This commit is contained in:
Flavio Wuensche 2019-10-28 22:41:11 +01:00
parent b69ac962ad
commit 712ef53c9a
3 changed files with 10 additions and 0 deletions

View file

@ -288,6 +288,7 @@ module ActiveRecord
# Sets the columns names the model should ignore. Ignored columns won't have attribute
# accessors defined, and won't be referenced in SQL queries.
def ignored_columns=(columns)
reload_schema_from_cache
@ignored_columns = columns.map(&:to_s)
end

View file

@ -1503,6 +1503,10 @@ class BasicsTest < ActiveRecord::TestCase
assert_equal "Developer: name", loaded_developer.name
end
test "when assigning new ignored columns it invalidates cache for column names" do
assert_not_includes ColumnNamesCachedDeveloper.column_names, "name"
end
test "ignored columns not included in SELECT" do
query = Developer.all.to_sql.downcase

View file

@ -303,3 +303,8 @@ class AttributedDeveloper < ActiveRecord::Base
self.ignored_columns += ["name"]
end
class ColumnNamesCachedDeveloper < ActiveRecord::Base
self.table_name = "developers"
self.ignored_columns += ["name"] if column_names.include?("name")
end