# Export fixture data that preserves foreign key/ActiveRecord associations?

**URL:** <https://www.ruby-forum.com/t/export-fixture-data-that-preserves-foreign-key-activerecord-associations/137513>\
**Category:** Rails\
**Created:** [May 13, 2008, 10:27pm UTC](https://www.ruby-forum.com/t/export-fixture-data-that-preserves-foreign-key-activerecord-associations/137513 "2008-05-13T22:27:33Z")\
**Posts on this page:** 1\
**Page:** 1

<div class="post-metadata">

**Author:** ![jfrankov](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/j/87869e/32.png) [@jfrankov](https://www.ruby-forum.com/u/jfrankov)\
**Post date:** [May 13, 2008, 10:27pm UTC](https://www.ruby-forum.com/t/export-fixture-data-that-preserves-foreign-key-activerecord-associations/137513/1 "2008-05-13T22:27:33Z")

</div>

I use the manage\_fixtures and fixture\_scenarios plugins (and they’re  
great) but neither one does what I really want: to export fixtures  
from a database that also exports any records associated with those  
fixtures. In other words, an intelligent export that follows foreign  
keys.

For example, if I had a cars table, and a car with id 1 that had a  
foreign key color\_id = 7, I’d want to export car 1 into the cars.yml  
fixture, and also color 7 into the colors.yml fixture.

Anyone know of a way to do this, or should I write one?

Thanks!  
-Jason
