# Mass update of associated models

**URL:** <https://www.ruby-forum.com/t/mass-update-of-associated-models/185060>\
**Category:** Rails\
**Created:** [March 12, 2010, 6:53pm UTC](https://www.ruby-forum.com/t/mass-update-of-associated-models/185060 "2010-03-12T18:53:43Z")\
**Posts on this page:** 1\
**Page:** 1

<div class="post-metadata">

**Author:** ![byrnejb](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/b/d2c977/32.png) [@byrnejb](https://www.ruby-forum.com/u/byrnejb)\
**Post date:** [March 12, 2010, 6:53pm UTC](https://www.ruby-forum.com/t/mass-update-of-associated-models/185060/1 "2010-03-12T18:53:43Z")

</div>

I am importing historical client data from a CODASYL DBMS into  
PostgreSQL via an xml document. I am at the point where I am  
implementing the actual inserts/updates using ActiveRecord. In the  
new system a Client belongs to a Correspondent.

In previous cases I have had to deal with only one model at a time.  
In that circumstance I added a class method called ‘load’ to the model  
class and passed it an array of hashes each containing the model  
attribute keys and values. In this case I have to divide the  
information in one xml node into two models.

My question is one of approach. Do I create each associated  
Correspondent model inside the Client class load method and parse all  
the data there? Or, do I have the controller script parse the data  
first, divide the data into two streams, and then call two separate  
#loads, one on the Correspondent model and one on the Client model?

Thoughts?
