Hello Everyone,
I have a Model for which there are many thousands (hundreds of thousands) of records. I'd like to update the value of one field for each record in a rake task. A ruby based function must be applied to this field for all records (i.e. can't perform the algorithm in an SQL UPDATE alone). First Thought: MyModel.find(:all).each { |m| m.my_field = function_call_here; m.save } Load all the models into memory, and I'd like to avoid that. Second Thought: Get the maximum "id" of the Model's records and program a loop, doing a "find_by_id" for each record. While the model does have an "id" field, some records have been deleted, so I would have to check that the "find_by_id" is nil... I'm not worried about new records being added to the database as this update will be run during a "maintenance" period. Anyone have any thoughts on how you would update every record for a model when you have a large number of records? Thank you for your time and help. -Jim --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk@googlegroups.com To unsubscribe from this group, send email to [EMAIL PROTECTED] For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---