title: How do I access information from multiple associated models in the Controller in an effiecient manner?
body: <p>First, some background.</p>
  
  <p>My application models are like so:</p>
  
  <pre><code>  User has_many :subscriptions; has_many :courses, :through =&gt; :subscriptions
  Subscription belongs_to :course, :user
    Course has_many :subscriptions; has_many :users, :through =&gt; :subscriptions
  </code></pre>
  
  <p>Subscription is a join table used to store information such as state (:active, :inactive, :failed, :passed, :unpaid) as well as serve as a connector to all the information that comes with taking a course (such as the Grade model(not yet added), the Payment model(work in progress), etc).</p>
  
  <p>I want to add the Payment model to store a history of payments on a subscription. Each payment can be for one or more subscriptions. So far, I've tried a <code>Payment has_many :subscriptions</code>, but <strong>I'm having trouble with the controller logic</strong> and I'm thinking maybe there's a better way to associate the models for "a Payment from a User on a Subscription to a Course."</p>
  
  <p>Technically speaking, in a payment show action, I would need information from each of these models (course.name, user_id of user who paid, payment.amount, all of which are connected to a Subscription) and in a Payment.create action, I'd need to set the state of the subscription (that I can do).</p>
  
  <p>If this is a logical/efficient way to associate the various models, how do I access the needed information(some information from each model course, user, payment, and subscription) in the Payment show action with minimal database calls? I'm using <code>Rails 3.2/Ruby 1.9</code> and would like to stick with ActiveRecord/ARel instead of straight sql statements. I'm open to "you're doing it wrong" answers as well. If changing the associations will make it more efficient to access the tables from the controller, I'm open to that as well.</p>