From 021bbc12babdee6b168eab81dd3c4a4f1bbeb9a9 Mon Sep 17 00:00:00 2001 From: Raphael Date: Tue, 11 Jan 2011 12:04:57 -0800 Subject: [PATCH] No guarantee that there aree join table rows for any given model --- lib/data_conversion/export_from_mongo.rb | 16 +++++++++++++--- 1 file changed, 13 insertions(+), 3 deletions(-) diff --git a/lib/data_conversion/export_from_mongo.rb b/lib/data_conversion/export_from_mongo.rb index 144062035..4f8058d2c 100644 --- a/lib/data_conversion/export_from_mongo.rb +++ b/lib/data_conversion/export_from_mongo.rb @@ -92,7 +92,11 @@ module DataConversion def contacts_json_to_csv model_hash generic_json_to_two_csvs(model_hash) do |hash| main_row = model_hash[:main_mongo_attrs].map { |attr_name| hash[attr_name] } - aspect_membership_rows = hash["aspect_ids"].map { |id| [hash["_id"], id] } + if hash["aspect_ids"] + aspect_membership_rows = hash["aspect_ids"].map { |id| [hash["_id"], id] } + else + aspect_membership_rows = [] + end [main_row, aspect_membership_rows] end #Also writes the aspect memberships csv @@ -173,7 +177,13 @@ module DataConversion generic_json_to_two_csvs(model_hash) do |hash| main_row = model_hash[:mongo_attrs].map { |attr_name| hash[attr_name] } - post_visibility_rows = hash["post_ids"].map { |id| [hash["_id"], id] } + + if hash["post_ids"] + post_visibility_rows = hash["post_ids"].map { |id| [hash["_id"], id] } + else + post_visibility_rows = [] + end + [main_row, post_visibility_rows] end end @@ -186,7 +196,7 @@ module DataConversion main_csv << model_hash[:main_attrs] join_csv = CSV.open("#{full_path}/csv/#{model_hash[:join_table_name]}.csv", 'w') - join_csv << model_hash[:join_table_attrs] + join_csv << model_hash[:join_table_attrs] unless model_hash[:join_table_attrs].empty? json_file.each do |aspect_json| hash = JSON.parse(aspect_json)