title: About Many-to-Many Associations: id is not saving to database
body: <p>I'm a beginner in rails and I'm studying Beginning Rails 4 3rd Edition:
  My rails' version is 4.2.4, Windows 8.1, and Ruby is 2.1.6.</p>
  
  <p>I have 3 models for Rich Many-to-Many Association:</p>
  
  <p>1- Comment</p>
  
  <p>2- Article</p>
  
  <p>3- User</p>
  
  <pre><code>class Comment &lt; ActiveRecord::Base
    belongs_to :article
  end
  
  class Article &lt; ActiveRecord::Base
    validates_presence_of :title
    validates_presence_of :body
  
    belongs_to :user
    has_and_belongs_to_many :categories
    has_many :comments
  
    def long_title
      "#{title} - #{published_at}"
    end
  end
  
  class User &lt; ActiveRecord::Base
    has_one :profile
    has_many :articles, -&gt; {order('published_at DESC, title ASC')},
                        :dependent =&gt; :nullify
    has_many :replies, :through =&gt; :articles, :source =&gt; :comments
  end
  </code></pre>
  
  <p>The issue I want to ask you about is that when I try to create a comment through this association, the comment created comes to have nil id, thus not saved to the database.</p>
  
  <p>For example, I tried the following in the rails console.</p>
  
  <pre><code>article.comments.create(name: 'Amumu', email: 'amu@daum.net', body: 'Amumu is lonely')
  </code></pre>
  
  <p>And I got the following result.</p>
  
  <pre><code>#&lt;Comment id: nil, article_id: 4, name: "Amumu", email: "amu@daum.net", body: "Amumu is lonely", created_at: nil, updated_at: nil&gt;
  </code></pre>
  
  <p>Why does the comment come to have a nil id? I expect it to have a automatically generated id, so saved to the database.</p>