rails how many foreign keys a table should have
<p>I have a rails4 app. I'm having the schema below and will add <code>post_replies</code> table that will <code>belong_to :post_comment</code> and <code>post_comment</code>will <code>has_many :post_replies</code>. The replies under comment will always belong to that given comment.</p>

<p>My question is that how many foreign key should be added to post_replies? I will always display them only on <code>post index page</code> and new reply will be added with <code>format_js</code>. <code>post_reply</code> <code>belongs_to post_comment</code> for sure, but should I use also both <code>belongs_to :user</code> and <code>belongs_to :post</code> ?</p>

<p>current schema:</p>

<pre><code>class User &lt; ActiveRecord::Base
  has_many :posts
  has_many :post_comments, through: :posts
end

class Post &lt; ActiveRecord::Base
  has_many :post_comments
  belongs_to :user
end

class PostComment &lt; ActiveRecord::Base
  belongs_to :post
  belongs_to :user
end
</code></pre>

<p>planned schema:</p>

<pre><code>class PostReply &lt; ActiveRecord::Base
  belongs_to :post_comment #this is needed for sure
  belongs_to :post #do i need this?
  belongs_To :user #and this?
end
</code></pre>

<p>routes:</p>

<pre><code>#current:

resources :posts do
  resources :post_comments, only: [:create, :update, :destroy], module: :posts
end

#and planning to add:

resources :post_comments, only: [] do 
  resources :post_repiles, only: [:create, :update, :destroy], module: :posts
end
</code></pre>