<?xml version="1.0" encoding="UTF-8"?>
<commit>
  <added type="array"/>
  <modified type="array">
    <modified>
      <diff>@@ -1,2 +1,3 @@
 .DS_Store
-*.log
\ No newline at end of file
+*.log
+pkg</diff>
      <filename>.gitignore</filename>
    </modified>
    <modified>
      <diff>@@ -8,11 +8,26 @@ class ActiveRecord::Base
     # Writes content of this table to db/table_name.yml, or the specified file.
     #
     # Writes all content by default, but can be limited.
-    def dump_to_file(path=nil, limit=nil)
-      opts = {}
+    def dump_to_file(path=nil, limit=nil, opts={})
       opts[:limit] = limit if limit
       path ||= &quot;db/#{table_name}.yml&quot;
       write_file(File.expand_path(path, RAILS_ROOT), self.find(:all, opts).to_yaml)
+      habtm_to_file
+    end
+
+    # dump the habtm association table
+    def habtm_to_file
+      path ||= &quot;db/#{table_name}.yml&quot;
+      joins = self.reflect_on_all_associations.select { |j|
+        j.macro == :has_and_belongs_to_many
+      }
+      joins.each do |join|
+        hsh = {}
+        connection.select_all(&quot;SELECT * FROM #{join.options[:join_table]}&quot;).each_with_index { |record, i|
+          hsh[&quot;join_#{'%05i' % i}&quot;] = record
+        }
+        write_file(File.expand_path(&quot;db/#{join.options[:join_table]}.yml&quot;, RAILS_ROOT), hsh.to_yaml(:SortKeys =&gt; true))
+      end
     end
 
     ##
@@ -33,9 +48,12 @@ class ActiveRecord::Base
       records = YAML::load( erb_data )
 
       records.each do |record|
-        puts &quot;______________&quot;
-        puts record.to_yaml
-        puts &quot;______________&quot;
+        unless 'test' == RAILS_ENV
+          puts &quot;______________&quot;
+          puts record.to_yaml
+          puts &quot;______________&quot;
+        end
+        
         record_copy = self.new(record.attributes)
         record_copy.id = record.id
 
@@ -57,13 +75,12 @@ class ActiveRecord::Base
     # Uses existing data in the database.
     #
     # Will be written to +test/fixtures/table_name.yml+. Can be restricted to some number of rows.
-    def to_fixture(limit=nil)
-      opts = {}
+    def to_fixture(limit=nil, key=nil, opts={})
       opts[:limit] = limit if limit
 
       write_file(File.expand_path(&quot;test/fixtures/#{table_name}.yml&quot;, RAILS_ROOT),
       self.find(:all, opts).inject({}) { |hsh, record|
-        hsh.merge(&quot;#{table_name.singularize}_#{'%05i' % record.id rescue record.id}&quot; =&gt; record.attributes)
+        hsh.merge((record.attributes[key.to_s] || &quot;#{table_name.singularize}_#{'%05i' % record.id rescue record.id}&quot;) =&gt; record.attributes)
       }.to_yaml(:SortKeys =&gt; true))
       habtm_to_fixture
     end</diff>
      <filename>lib/ar_fixtures.rb</filename>
    </modified>
    <modified>
      <diff>@@ -29,12 +29,19 @@ class ArFixturesTest &lt; Test::Unit::TestCase
     assert_equal 2, Beer.count, &quot;#{Beer.find(:all).to_yaml}&quot;
   end
 
+  def test_habtm_to_file
+    Beer.habtm_to_file
+    assert File.exist?(File.join(RAILS_ROOT, 'db', 'beers_drunkards.yml'))
+  end
+
   def test_load_from_file
-    cp  File.join(RAILS_ROOT, 'fixtures', 'glasses.yml'), 
-        File.join(RAILS_ROOT, 'db', 'glasses.yml')
-    assert_equal 0, Glass.count
-    Glass.load_from_file
-    assert_equal 2, Glass.count
+    cp  File.join(RAILS_ROOT, 'fixtures', 'beers.yml'), 
+        File.join(RAILS_ROOT, 'db', 'beers.yml')
+    cp  File.join(RAILS_ROOT, 'fixtures', 'beers_drunkards.yml'), 
+        File.join(RAILS_ROOT, 'db', 'beers_drunkards.yml')
+    Beer.load_from_file
+    assert_equal 2, Beer.count
+    # assert_equal 1, Beer.find(1).drunkards.size
   end
 
   def test_to_fixture</diff>
      <filename>test/ar_fixtures_test.rb</filename>
    </modified>
    <modified>
      <diff>@@ -1,10 +1,13 @@
-stout:
-  id: 1
-  name: stout
-  rating: 5
-  sipped_at: &lt;%= Time.now %&gt;
-ipa:
-  id: 2
-  name: india pale ale
-  rating: 4
-  sipped_at: &lt;%= Time.now - 60 %&gt;
+--- 
+- !ruby/object:Beer
+  attributes:
+    id: 1
+    name: stout
+    rating: 5
+    sipped_at: &lt;%= Time.now %&gt;
+- !ruby/object:Beer
+  attributes:
+    id: 2
+    name: india pale ale
+    rating: 4
+    sipped_at: &lt;%= Time.now - 60 %&gt;</diff>
      <filename>test/fixtures/beers.yml</filename>
    </modified>
    <modified>
      <diff>@@ -16,6 +16,8 @@ load(File.dirname(__FILE__) + &quot;/schema.rb&quot;) if File.exist?(File.dirname(__FILE__
 Test::Unit::TestCase.fixture_path = File.dirname(__FILE__) + &quot;/fixtures/&quot;
 $LOAD_PATH.unshift(Test::Unit::TestCase.fixture_path)
 
+RAILS_ENV = 'test' unless defined?(RAILS_ENV)
+
 class Test::Unit::TestCase #:nodoc:
   def create_fixtures(*table_names)
     if block_given?</diff>
      <filename>test/test_helper.rb</filename>
    </modified>
  </modified>
  <removed type="array"/>
  <parents type="array">
    <parent>
      <id>1c5eb71e253a29225b3f5491ff802550f635a5f5</id>
    </parent>
  </parents>
  <author>
    <name>Geoffrey Grosenbach</name>
    <email>boss@topfunky.com</email>
  </author>
  <url>http://github.com/topfunky/ar_fixtures/commit/2c8b7cb1903a23b3309a2b6103fb5d01af5d7194</url>
  <id>2c8b7cb1903a23b3309a2b6103fb5d01af5d7194</id>
  <committed-date>2008-11-13T13:06:39-08:00</committed-date>
  <authored-date>2008-11-13T13:06:39-08:00</authored-date>
  <message>Better handling of options and HABTM tables. [UnderpantsGnome]</message>
  <tree>d89108578ddbeafc0bee1b84a5706e8ffd4114ac</tree>
  <committer>
    <name>Geoffrey Grosenbach</name>
    <email>boss@topfunky.com</email>
  </committer>
</commit>
