title: What's the right way to query multiple associations in Rails?
body: <p>My application models a writing competition, with <code>Users</code>, <code>Stories</code>, <code>Competitions</code> and <code>Submissions</code>.</p>
  
  <p>Users can participate in competitions through submissions, or as owners. I'd like one query or method that returns all competitions owned or participated in by a user. I've got a method returning those as an array, <code>competitions | owned_competitions</code>, but I'd really like to keep them ActiveRecord entities so I can chain, apply scopes, etc.</p>
  
  <p>Is there a way to do that, or a better way to setup these relationships?</p>
  
  <p>My models look like this:</p>
  
  <p>user.rb:</p>
  
  <pre><code>has_many :stories
  has_many :submissions
  has_many :competitions, :through =&gt; :submissions
  has_many :owned_competitions, :class_name =&gt; "Competition"
  </code></pre>
  
  <p>story.rb:</p>
  
  <pre><code>belongs_to :user
  has_many :submissions
  has_many :competitions, :through =&gt; :submissions
  </code></pre>
  
  <p>competition.rb:</p>
  
  <pre><code>belongs_to :owner, :class_name =&gt; "User", :foreign_key =&gt; 'user_id'
  has_many :submissions
  has_many :competitors, :through =&gt; :submissions, :source =&gt; :user
  has_many :stories, :through =&gt; :submissions
  
  scope :expiring_today, lambda { where("deadline = ?", Date.today) }
  </code></pre>
  
  <p>submission.rb:</p>
  
  <pre><code>belongs_to :user
  belongs_to :story
  belongs_to :competition
  </code></pre>