aboutsummaryrefslogtreecommitdiffstats
path: root/activerecord/lib/active_record
diff options
context:
space:
mode:
authorAaron Patterson <aaron.patterson@gmail.com>2013-09-06 11:38:28 -0700
committerAaron Patterson <aaron.patterson@gmail.com>2013-09-06 11:38:28 -0700
commitea55d86eb110842347351c2b15b4103ed62172fb (patch)
tree796f24b53d8e9f8ea61a616abe4caa326fef11e7 /activerecord/lib/active_record
parentcd85615046a409f84e7a96900c5fb4037d3bc2e1 (diff)
downloadrails-ea55d86eb110842347351c2b15b4103ed62172fb.tar.gz
rails-ea55d86eb110842347351c2b15b4103ed62172fb.tar.bz2
rails-ea55d86eb110842347351c2b15b4103ed62172fb.zip
reduce duplication somewhat
Diffstat (limited to 'activerecord/lib/active_record')
-rw-r--r--activerecord/lib/active_record/fixtures.rb28
1 files changed, 14 insertions, 14 deletions
diff --git a/activerecord/lib/active_record/fixtures.rb b/activerecord/lib/active_record/fixtures.rb
index 5b4d87df7a..0e96de518d 100644
--- a/activerecord/lib/active_record/fixtures.rb
+++ b/activerecord/lib/active_record/fixtures.rb
@@ -643,33 +643,33 @@ module ActiveRecord
@primary_key_name ||= model_class && model_class.primary_key
end
+ def join_rows(targets, row, lhs_key, rhs_key)
+ targets = targets.is_a?(Array) ? targets : targets.split(/\s*,\s*/)
+ targets.map { |target|
+ { lhs_key => row[primary_key_name],
+ rhs_key => ActiveRecord::FixtureSet.identify(target) }
+ }
+ end
+
def handle_hmt(rows, row, association)
# This is the case when the join table has no fixtures file
if (targets = row.delete(association.name.to_s))
- targets = targets.is_a?(Array) ? targets : targets.split(/\s*,\s*/)
table_name = association.join_table
- lhs_key = association.through_reflection.foreign_key
- rhs_key = association.foreign_key
+ lhs_key = association.through_reflection.foreign_key
+ rhs_key = association.foreign_key
- rows[table_name].concat targets.map { |target|
- { lhs_key => row[primary_key_name],
- rhs_key => ActiveRecord::FixtureSet.identify(target) }
- }
+ rows[table_name].concat join_rows(targets, row, lhs_key, rhs_key)
end
end
def handle_habtm(rows, row, association)
# This is the case when the join table has no fixtures file
if (targets = row.delete(association.name.to_s))
- targets = targets.is_a?(Array) ? targets : targets.split(/\s*,\s*/)
table_name = association.join_table
- lhs_key = association.foreign_key
- rhs_key = association.association_foreign_key
+ lhs_key = association.foreign_key
+ rhs_key = association.association_foreign_key
- rows[table_name].concat targets.map { |target|
- { lhs_key => row[primary_key_name],
- rhs_key => ActiveRecord::FixtureSet.identify(target) }
- }
+ rows[table_name].concat join_rows(targets, row, lhs_key, rhs_key)
end
end