diff options
author | Sean Griffin <sean@thoughtbot.com> | 2014-12-22 12:06:01 -0700 |
---|---|---|
committer | Sean Griffin <sean@thoughtbot.com> | 2014-12-22 13:47:10 -0700 |
commit | a9c0c46263dcafcf01944246e31cbe5650ee605e (patch) | |
tree | c4478d8fc91c6cd01d696332e393a3c12dca0543 /activerecord | |
parent | 9fff631a06d72e3b9d7a89b9c8f45b9accf69859 (diff) | |
download | rails-a9c0c46263dcafcf01944246e31cbe5650ee605e.tar.gz rails-a9c0c46263dcafcf01944246e31cbe5650ee605e.tar.bz2 rails-a9c0c46263dcafcf01944246e31cbe5650ee605e.zip |
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.
Diffstat (limited to 'activerecord')
-rw-r--r-- | activerecord/lib/active_record/connection_adapters/abstract/schema_definitions.rb | 24 |
1 files changed, 17 insertions, 7 deletions
diff --git a/activerecord/lib/active_record/connection_adapters/abstract/schema_definitions.rb b/activerecord/lib/active_record/connection_adapters/abstract/schema_definitions.rb index 537e21029e..33419680fb 100644 --- a/activerecord/lib/active_record/connection_adapters/abstract/schema_definitions.rb +++ b/activerecord/lib/active_record/connection_adapters/abstract/schema_definitions.rb @@ -306,15 +306,25 @@ module ActiveRecord # 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 |