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

Don't pass useless table_name to ModelMetadata.new

The `model_metadata` is only used if `model_class` is given.

If `model_class` is given, the `table_name` is always
`model_class.table_name`.
This commit is contained in:
Ryuta Kamizono 2018-11-03 22:35:23 +09:00
parent 1812240f1a
commit 06ef4c3fa8
3 changed files with 4 additions and 13 deletions

View file

@ -3,9 +3,8 @@
module ActiveRecord
class FixtureSet
class ModelMetadata # :nodoc:
def initialize(model_class, table_name)
def initialize(model_class)
@model_class = model_class
@table_name = table_name
end
def primary_key_name
@ -23,18 +22,12 @@ module ActiveRecord
def timestamp_column_names
@timestamp_column_names ||=
%w(created_at created_on updated_at updated_on) & column_names
%w(created_at created_on updated_at updated_on) & @model_class.column_names
end
def inheritance_column_name
@inheritance_column_name ||= @model_class && @model_class.inheritance_column
end
private
def column_names
@column_names ||= @model_class.connection.columns(@table_name).collect(&:name)
end
end
end
end

View file

@ -58,7 +58,7 @@ module ActiveRecord
end
def model_metadata
@model_metadata ||= ModelMetadata.new(model_class, table_name)
@model_metadata ||= ModelMetadata.new(model_class)
end
def resolve_sti_reflections(row)

View file

@ -629,9 +629,7 @@ module ActiveRecord
@fixtures = read_fixture_files(path)
@table_name = (model_class.respond_to?(:table_name) ?
model_class.table_name :
self.class.default_fixture_table_name(name, config))
@table_name = model_class&.table_name || self.class.default_fixture_table_name(name, config)
end
def [](x)