Convert references to kwargs

While we aren't taking PRs with these kinds of changes just yet, they
are fine if we're actively working on the method and it makes things
easier.
This commit is contained in:
Sean Griffin 2014-12-22 12:06:01 -07:00
parent 9fff631a06
commit a9c0c46263

@ -306,15 +306,25 @@ def timestamps(*args)
# t.belongs_to(:supplier, polymorphic: true)
#
# See SchemaStatements#add_reference
def references(*args)
options = args.extract_options!
polymorphic = options.delete(:polymorphic)
index_options = options.delete(:index)
type = options.delete(:type) || :integer
def references(
*args,
polymorphic: false,
index: false,
type: :integer,
**options
)
polymorphic_options = polymorphic.is_a?(Hash) ? polymorphic : options
index_options = index.is_a?(Hash) ? index : {}
args.each do |col|
column("#{col}_id", type, options)
column("#{col}_type", :string, polymorphic.is_a?(Hash) ? polymorphic : options) if polymorphic
index(polymorphic ? %w(type id).map { |t| "#{col}_#{t}" } : "#{col}_id", index_options.is_a?(Hash) ? index_options : {}) if index_options
if polymorphic
column("#{col}_type", :string, polymorphic_options)
end
if index
self.index(polymorphic ? %w(type id).map { |t| "#{col}_#{t}" } : "#{col}_id", index_options)
end
end
end
alias :belongs_to :references