title: Advice on setting up Rails model with multiple relations (belongs_to)
body: <p>About to make a design decision and looking for a little validation or advice on the "Rails way" before proceeding. </p>
  
  <p>Summary: </p>
  
  <ul>
  <li><strong>Users</strong> create <strong>Posts</strong></li>
  <li>Posts can include (one or more) <strong>Photos</strong></li>
  <li>Posts can be (optionally) related to an <strong>Event</strong></li>
  <li>In turn Photos from a Post are also related to said Event</li>
  </ul>
  
  <p>One requirement, among others, would be to easily display all Photos from a given Event. Another would be showing all Photos submitted by a given User.</p>
  
  <p>I originally assumed:</p>
  
  <pre><code>class Photo &lt; ActiveRecord::Base
    belongs_to :post
    belongs_to :user
    belongs_to :event
  ...
  end
  </code></pre>
  
  <p>But I'm having trouble building all the relationships in the Post controller: </p>
  
  <pre><code>class PostsController &lt; ApplicationController
    before_filter :login_required, :except =&gt; [:index, :show]
  
    def create
      @user = User.find(session[:user_id])
      @post = @user.posts.create(params[:post])
      # how/where to assign Event?
      ...
    end
    ...
  end
  </code></pre>
  
  <p>I can loop through and <code>build</code> each <code>:photo</code> param in the Post model...but not sure how/where to assign the <code>event_id</code>? Which makes me wonder if maybe there's a better approach? </p>
  
  <p>Perhaps I should be exploring <code>has_many :through</code> relationships where: </p>
  
  <p>User <code>has_many :photos, :through =&gt; :posts</code></p>
  
  <p>Event <code>has_many :photos, :through =&gt; :posts</code></p>
  
  <p>In a nutshell, <strong>should I be storing the user_id &amp; event_id in every Photo to make it easier to grab them as needed?</strong> If so, how best to assign the associations? Or, will this become hard to maintain and thus generally frowned upon and I should use a <code>has_many :through</code> approach?</p>