mirror of
https://github.com/rails/rails.git
synced 2022-11-09 12:12:34 -05:00
Extract repeatedly appeared prepending compatible table definition
This commit is contained in:
parent
bd2542b74f
commit
214dc7d82d
1 changed files with 24 additions and 25 deletions
|
@ -52,11 +52,8 @@ module ActiveRecord
|
|||
end
|
||||
|
||||
if block_given?
|
||||
super(table_name, options) do |t|
|
||||
class << t
|
||||
prepend TableDefinition
|
||||
end
|
||||
yield t
|
||||
super do |t|
|
||||
yield compatible_table_definition(t)
|
||||
end
|
||||
else
|
||||
super
|
||||
|
@ -65,11 +62,8 @@ module ActiveRecord
|
|||
|
||||
def change_table(table_name, options = {})
|
||||
if block_given?
|
||||
super(table_name, options) do |t|
|
||||
class << t
|
||||
prepend TableDefinition
|
||||
end
|
||||
yield t
|
||||
super do |t|
|
||||
yield compatible_table_definition(t)
|
||||
end
|
||||
else
|
||||
super
|
||||
|
@ -80,11 +74,8 @@ module ActiveRecord
|
|||
column_options.reverse_merge!(type: :integer)
|
||||
|
||||
if block_given?
|
||||
super(table_1, table_2, column_options: column_options, **options) do |t|
|
||||
class << t
|
||||
prepend TableDefinition
|
||||
end
|
||||
yield t
|
||||
super do |t|
|
||||
yield compatible_table_definition(t)
|
||||
end
|
||||
else
|
||||
super
|
||||
|
@ -103,6 +94,14 @@ module ActiveRecord
|
|||
super(table_name, ref_name, type: :integer, **options)
|
||||
end
|
||||
alias :add_belongs_to :add_reference
|
||||
|
||||
private
|
||||
def compatible_table_definition(t)
|
||||
class << t
|
||||
prepend TableDefinition
|
||||
end
|
||||
t
|
||||
end
|
||||
end
|
||||
|
||||
class V4_2 < V5_0
|
||||
|
@ -121,11 +120,8 @@ module ActiveRecord
|
|||
|
||||
def create_table(table_name, options = {})
|
||||
if block_given?
|
||||
super(table_name, options) do |t|
|
||||
class << t
|
||||
prepend TableDefinition
|
||||
end
|
||||
yield t
|
||||
super do |t|
|
||||
yield compatible_table_definition(t)
|
||||
end
|
||||
else
|
||||
super
|
||||
|
@ -134,11 +130,8 @@ module ActiveRecord
|
|||
|
||||
def change_table(table_name, options = {})
|
||||
if block_given?
|
||||
super(table_name, options) do |t|
|
||||
class << t
|
||||
prepend TableDefinition
|
||||
end
|
||||
yield t
|
||||
super do |t|
|
||||
yield compatible_table_definition(t)
|
||||
end
|
||||
else
|
||||
super
|
||||
|
@ -174,6 +167,12 @@ module ActiveRecord
|
|||
end
|
||||
|
||||
private
|
||||
def compatible_table_definition(t)
|
||||
class << t
|
||||
prepend TableDefinition
|
||||
end
|
||||
t
|
||||
end
|
||||
|
||||
def index_name_for_remove(table_name, options = {})
|
||||
index_name = index_name(table_name, options)
|
||||
|
|
Loading…
Reference in a new issue