title: Bulk inserting new model instances using an hmt relation
body: <p>I have two models with a "has_many, through" relationship as defined by these definitions:</p>
  
  <pre><code>class TabAccount &lt; ApplicationRecord
    has_many :tab_community_accounts
    has_many :tab_communities, through: :tab_community_accounts
  end
  
  class TabCommunity &lt; ApplicationRecord
    has_many :tab_community_accounts
    has_many :tab_accounts, through: :tab_community_accounts
  end
  
  class TabCommunityAccount &lt; ApplicationRecord
    belongs_to :tab_community
    belongs_to :tab_account
  end
  </code></pre>
  
  <p>I want to bulk add new accounts from a CSV file after I create a new community. This does not generate an error:</p>
  
  <pre><code>_upload_dir = &lt;string&gt;
  _import_filename = &lt;string&gt;
  _community_name = &lt;string&gt;
  _this_community = TabCommunity.find_by_name(_community_name)
  
  File.foreach("#{_upload_dir}/#{_import_filename}") do |csv_row_raw|
    csv_row = csv_row_raw.split(",")
    _screen_name = csv_row[0].strip
    _this_community.tab_accounts.first_or_create!({screen_name: _screen_name, ref_platform_id: RefPlatform.find_by_name("Twitter").id})
  end
  </code></pre>
  
  <p>But it only inserts a new account and <code>hmt</code> relation for the first row from the CSV file. I want to use <code>.first_or_create()</code> because the account might already exist in the database. I added <code>put</code> statements inside the <code>foreach</code> before and after <code>.first_or_create()</code> and they do print for each row, but only the 1st row and its relation is saved in my database. Can anyone clue me in as to how I can dump the rest of the rows? I suspect I'm close.</p>