SD Ruby, What's the most efficient way to update a large batch of ActiveRecord model instances where the same fields are not being updated for each model?
Here's the setup: I've got a database of members (about 13,000) and a CSV file that has contact information (3 phone numbers and 3 email addresses) for a subset of the members (say, 350). Each row of the CSV file may have between 0 and 6 of the contact fields filled in. There also might be data in those same fields in each database entry for the same member. What I'm trying to do is update any field in the database that's empty with the corresponding attribute in the CSV file for that member that isn't blank. The brute-force approach is to just loop through all 350 members in the CSV file (which contains the primary key of the associated database table) and update the attributes with the non-null CSV data. Each SQL update statement will be different since there are 6 fields that could potentially be updated. This seems painfully inefficient to me. An ActiveRecord udpate_all call won't work here since each update statement has to be uniquely constructed. Can anyone suggest a better approach? Cheers, Chris -- SD Ruby mailing list [email protected] http://groups.google.com/group/sdruby
