title: rake db:seed populate keys when seed
body: <p>I have state data in a txt file that I used to seed my States db which has columns :id and :name. the :name is the state 2-digit code. Used the following code in seeds.rb file:</p>
  
  <pre><code>State.delete_all
  open("C:/Sites/rails_projects/sales_tracking/lib/assets/states.txt") do |states|
    states.read.each_line do |state|
    name = state
    State.create!(:name =&gt; name)
   end
  end
  </code></pre>
  
  <p>I now have my Cities.txt file with data of city,state.  My cities db has columns :id, :name, :state_id.  :state_id is the foreign key from the states table.  What code do I need to add to the below part of my seeds.rb file to populate the :state_id while running rake db:seed on the city seed data ("code" is 2-digit state id).</p>
  
  <pre><code>City.delete_all
  open("C:/Sites/rails_projects/sales_tracking/lib/assets/cities.txt") do |cities|
    cities.read.each_line do |city|
      name, code = city.chomp.split(",")
       ??
      City.create!(:name =&gt; name, :state_id =&gt; state_id)
    end
  end
  </code></pre>