title: Associated object not created, duplicate empty insert statement created for original object created (Rails)
body: <p>
  I have a fairly simple has many / belongs to relationship model: Reports have many Records have many Related Publishers. The belongs to objects have a foreign key to ID their parent.</p>
  
  <p>However, I cannot save any 'Related Publishers'. Or rather I 'can', where the commit transaction returns true, but the Related Record is not created and the corresponding SQLite3 command does not make sense.</p>
  
  <p>Why is the SQLite action generated by Rails the command to create an empty Record? Why is the save of the Related Publishers circumvented?</p>
  
  <p>In <code>rails console</code>, with some output truncated</p>
  
  <pre class="lang-rb prettyprint-override"><code>&gt; @report = Report.new =&gt; #&lt;Report id: nil, ... &gt;
  &gt; @record = @report.records.build(leid: 1234567890) =&gt; #&lt;Record id: nil, leid: 1234567890, ...&gt;
  &gt; @related_publisher = @record.related_publishers.build(sid: 9876)
   =&gt; #&lt;RelatedPublisher id: nil, ..., sid: 9876, ...&gt;
  &gt; @report.save
     (0.1ms)  begin transaction
    SQL (4.5ms)  INSERT INTO "reports" ("created_at", "updated_at") VALUES (?, ?)  [["created_at", Wed, 07 May 2014 11:20:50 UTC +00:00], ["updated_at", Wed, 07 May 2014 11:20:50 UTC +00:00]]
    SQL (0.2ms)  INSERT INTO "records" ("created_at", "leid", "report_id", "updated_at") VALUES (?, ?, ?, ?)  [["created_at", Wed, 07 May 2014 11:20:50 UTC +00:00], ["leid", 1234567890], ["report_id", 22], ["updated_at", Wed, 07 May 2014 11:20:50 UTC +00:00]]
    SQL (0.3ms)  INSERT INTO "records" ("created_at", "updated_at") VALUES (?, ?)  [["created_at", Wed, 07 May 2014 11:20:50 UTC +00:00], ["updated_at", Wed, 07 May 2014 11:20:50 UTC +00:00]]
     (0.7ms)  commit transaction
   =&gt; true
  &gt; RelatedPublisher.all
  RelatedPublisher Load (0.3ms)  SELECT "related_publishers".* FROM "related_publishers"
   =&gt; #&lt;ActiveRecord::Relation []&gt;
  </code></pre>
  
  <p>(Using Rails 4.0.4 with sqlite3 3.7.13 with gem version 1.3.9 and Ruby 2.0.0p353 on Mac OSX 10.9.2</p>
  
  <hr>
  
  <p>app/models/report.rb</p>
  
  <pre class="lang-rb prettyprint-override"><code>class Report &lt; ActiveRecord::Base
    has_many :records
  end
  </code></pre>
  
  <p>app/models/record.rb</p>
  
  <pre class="lang-rb prettyprint-override"><code>class Record &lt; ActiveRecord::Base
    belongs_to :report
  
    has_many :related_publishers
  end
  </code></pre>
  
  <p>app/models/related_publisher.rb</p>
  
  <pre class="lang-rb prettyprint-override"><code>class RelatedPublisher &lt; ActiveRecord::Base
    belongs_to :record
  end
  </code></pre>
  
  <hr>
  
  <p>From <code>schema.rb</code></p>
  
  <pre class="lang-rb prettyprint-override"><code>  create_table "records", force: true do |t|
      t.integer  "leid"
      t.integer  "sid"
      t.string   "name"
      t.string   "url"
      t.string   "join_date"
      t.string   "join_ip"
      t.string   "country"
      t.datetime "created_at"
      t.datetime "updated_at"
      t.integer  "report_id"
      t.boolean  "ipAddressMatch"
      t.boolean  "whoisAddressMatch"
      t.integer  "recommendation"
    end
  
    add_index "records", ["report_id"], name: "index_records_on_report_id"
  
    create_table "related_publishers", force: true do |t|
      t.integer  "leid"
      t.integer  "sid"
      t.string   "name"
      t.string   "url"
      t.string   "join_date"
      t.string   "join_ip"
      t.string   "country"
      t.integer  "record_id"
      t.datetime "created_at"
      t.datetime "updated_at"
    end
  
    add_index "related_publishers", ["record_id"], name: "index_related_publishers_on_record_id"
  
    create_table "reports", force: true do |t|
      t.integer  "report_type"
      t.string   "upload_data_file_path"
      t.string   "completed_data_file_path"
      t.datetime "created_at"
      t.datetime "updated_at"
      t.string   "ltn_username"
    end
  </code></pre>