title: Associating two tables that both belong to a third, independent table
body: <p>I have three tables:</p>
  
  <pre><code>Topics        Jobs          Requests
  -----         ----          --------
  title         description   request
  description   worker_id     user_id   
                topic_id      worker_id
                              topic_id
  </code></pre>
  
  <p>Workers create a job for each Topic. Users can then request the worker to do that job.</p>
  
  <p>My current associations:</p>
  
  <pre><code>class Topic &lt; AR::Base
    has_many :jobs
    has_many :worker, through: :jobs
  end
  
  class Job &lt; AR::Base
    belongs_to :topic
    belongs_to :worker
    has_many :requests
  end
  
  class Request &lt; AR::Base
    belongs_to :user
    belongs_to :worker
    belongs_to :topic
    has_one: :job, through: :topic   #This doesn't work, lol.
  end
  </code></pre>
  
  <p>The problem:</p>
  
  <p>I'm not sure if a Request should belong to a Topic, or a Job.</p>
  
  <p>I need to:</p>
  
  <ul>
  <li><p>access a request's topic info more often than the job info, but still have the job info available.</p></li>
  <li><p>create a request based on the topic and worker, not the job. (This is important.) </p></li>
  <li><p>list all requests for a given topic.</p></li>
  <li><p>preload topic and job info for requests. (Also important.)</p></li>
  </ul>
  
  <p>I'm hesitant to directly associate Requests and Jobs because Jobs contains some info that should not be available to all requests. With that association any request could access that info, but maybe that's not a huge deal.</p>
  
  <p>Also, because I need such a close association between Requests and Topics, it seems more logical to go with that association, but then I lose easy Job access. (With the above associations I have to use a custom method: <code>Job.find_by(topic_id: self.topic_id, worker_id: self.worker_id)</code> which doesn't allow for preloading or multiple requests.)</p>
  
  <p>What's the best way to go here?</p>
  
  <p>(Let me know if there's a better title.)</p>