Skip to content

Commit db48ee3

Browse files
committed
call to_s on value passed to table_name=
1 parent ba5a334 commit db48ee3

File tree

2 files changed

+6
-1
lines changed

2 files changed

+6
-1
lines changed

activerecord/lib/active_record/model_schema.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -115,7 +115,7 @@ def table_name
115115
# the documentation for ActiveRecord::Base#table_name.
116116
def table_name=(value)
117117
@original_table_name = @table_name if defined?(@table_name)
118-
@table_name = value
118+
@table_name = value && value.to_s
119119
@quoted_table_name = nil
120120
@arel_table = nil
121121
@relation = Relation.new(self, arel_table)

activerecord/test/cases/base_test.rb

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1446,6 +1446,11 @@ def test_switching_between_table_name
14461446
end
14471447
end
14481448

1449+
def test_set_table_name_symbol_converted_to_string
1450+
Joke.table_name = :cold_jokes
1451+
assert_equal 'cold_jokes', Joke.table_name
1452+
end
1453+
14491454
def test_quoted_table_name_after_set_table_name
14501455
klass = Class.new(ActiveRecord::Base)
14511456

0 commit comments

Comments
 (0)