title: Rails testing - Fixtures for has_many associations
body: <p>I am new to unit testing and have a simple use case.</p>
  
  <p>There are 2 models: <strong>City</strong>, <strong>Resident</strong>. A City has_many Residents.</p>
  
  <p>I created 2 fixture yml files: cities.yml, residents.yml.</p>
  
  <p><strong>residents.yml</strong></p>
  
  <pre><code>resident1:
    name: resident1
  
  resident2:
    name: resident2
  
  resident3:
    name: resident3
  </code></pre>
  
  <p><strong>cities.yml</strong></p>
  
  <pre><code>city1:
    name: city1
    residents: resident1, resident2, resident3
  </code></pre>
  
  <p>When I run a trivial test that should always pass, I get an <strong>error</strong>:</p>
  
  <pre><code>Minitest::UnexpectedError: ActiveRecord::StatementInvalid: Mysql2::Error: Unknown column 'residents' in 'field list': INSERT INTO `cities` (`name`, `residents`, `created_at`, `updated_at`, `id`) VALUES ('city1', 'resident1, resident2, resident3', '2014-06-09 20:42:22', '2014-06-09 20:42:22', 574963714)
  </code></pre>
  
  <p>What I <strong>expected</strong> is to have a City model instance with a property <code>name: 'city1'</code>, and a property <code>residents</code> an array of 3 Resident model instances. </p>
  
  <p>Inside the City.rb, I specified has_many relation to the Resident model. And inside Resident.rb I specified belongs_to relation to the City model.</p>
  
  <p>This should be a simple thing to do, shouldn't it?</p>
  
  <p><strong>UPDATE #1:</strong></p>
  
  <p>It seems it is only possible to do it by setting the city property for the Resident fixtures.</p>
  
  <p><strong>residents.yml</strong></p>
  
  <pre><code>resident1:
    name: resident1
    city: city1 # added
  
  resident2:
    name: resident2
    city: city1 # added
  
  resident3:
    name: resident3
    city: city1 # added
  </code></pre>
  
  <p><strong>cities.yml</strong></p>
  
  <pre><code>city1:
    name: city1
    # residents: resident1, resident2, resident3
  </code></pre>
  
  <p>I guess it will have to suffice.</p>