[Rails] AR: How to store and restore in YML.
Jake Janovetz
jakejanovetz at yahoo.com
Mon Jan 2 00:20:28 GMT 2006
Hello-
I have a database with entries that are segmented by customers. I would
like to be able to store / delete / restore a particular customer's
information. I will need to rebuild the rows on restore and also
rebuild the associations for the different tables.
For example,
customer {
id
name
}
companies {
id
customer_id (belongs_to)
name
}
contacts {
id
company_id (belongs_to)
name
}
So, if I just write out YML for the rows in this database, I'd end up
with something like:
Customer: id=34, name="Bob"
Company: id=134, customer_id=34, name="Intel"
Company: id=149, customer_id=34, name="Apple"
Contact: id=9383, company_id=134, name="Jerry"
Contact: id=8392, company_id=149, name="Robert"
The problem with this is that it is more difficult to regenerate those
rows because the associations would need to be broken and rebuilt.
What I would like to do is use the names in the YML output so I can
create records in a valid order, and do "finds" to find the right
records for associations. (Uniqueness is enforced so a find will find a
single record)
Customer: id=34, name="Bob"
Company: id=134, customer_id="Bob", name="Intel"
Company: id=149, customer_id="Bob", name="Apple"
Contact: id=9383, company_id="Intel", name="Jerry"
Contact: id=8392, company_id="Apple", name="Robert"
I am interested in hearing any rails/ruby tricks that would help me do
this for a number of different tables in the database.
Any suggestions?
Jake
--
Posted via http://www.ruby-forum.com/.
More information about the Rails
mailing list