diff options
author | Aaron Patterson <aaron.patterson@gmail.com> | 2013-08-01 17:46:44 -0700 |
---|---|---|
committer | Aaron Patterson <aaron.patterson@gmail.com> | 2013-08-01 17:46:44 -0700 |
commit | 5753a8cb2a63284aeb30d5b46e28301478cb779e (patch) | |
tree | ad5184a2e4d781a4e91cb107a1c377dfd66ac02b | |
parent | 7db93131ed01aa3b64774b81f6c6b78a6012a75a (diff) | |
download | rails-5753a8cb2a63284aeb30d5b46e28301478cb779e.tar.gz rails-5753a8cb2a63284aeb30d5b46e28301478cb779e.tar.bz2 rails-5753a8cb2a63284aeb30d5b46e28301478cb779e.zip |
extract habtm handling to a method
-rw-r--r-- | activerecord/lib/active_record/fixtures.rb | 20 |
1 files changed, 12 insertions, 8 deletions
diff --git a/activerecord/lib/active_record/fixtures.rb b/activerecord/lib/active_record/fixtures.rb index 47d4f3637f..20ca4e3c91 100644 --- a/activerecord/lib/active_record/fixtures.rb +++ b/activerecord/lib/active_record/fixtures.rb @@ -592,14 +592,7 @@ module ActiveRecord row[fk_name] = ActiveRecord::FixtureSet.identify(value) end when :has_and_belongs_to_many - if (targets = row.delete(association.name.to_s)) - targets = targets.is_a?(Array) ? targets : targets.split(/\s*,\s*/) - table_name = association.join_table - rows[table_name].concat targets.map { |target| - { association.foreign_key => row[primary_key_name], - association.association_foreign_key => ActiveRecord::FixtureSet.identify(target) } - } - end + handle_habtm(rows, row, association) end end end @@ -614,6 +607,17 @@ module ActiveRecord @primary_key_name ||= model_class && model_class.primary_key end + def handle_habtm(rows, row, association) + if (targets = row.delete(association.name.to_s)) + targets = targets.is_a?(Array) ? targets : targets.split(/\s*,\s*/) + table_name = association.join_table + rows[table_name].concat targets.map { |target| + { association.foreign_key => row[primary_key_name], + association.association_foreign_key => ActiveRecord::FixtureSet.identify(target) } + } + end + end + def has_primary_key_column? @has_primary_key_column ||= primary_key_name && model_class.columns.any? { |c| c.name == primary_key_name } |