title: Rails - Logic for finding info from a :has_many :through needed!
body: <p>I have 3 relevant tables.
  User, Orders, and Viewables</p>
  
  <p>The idea is that each User has got many Orders, but at the same time, each User can View specific other Orders that belong to other Users. So Viewables has the attributes of <code>user_id</code> and <code>order_id</code>.</p>
  
  <p>Orders has a 
  <code>:has_many :Users, :through =&gt; :viewables</code></p>
  
  <p>Is it possible to do a find through an Order's view?
  So something like </p>
  
  <p>@viewable_orders = Orders.find(:all, :conditions => ["Viewable.user_id=?",1])</p>
  
  <p>To get a list of Orders which are viewable by user_id=1. (This doesn't work, else I won't be asking. :( )
  The idea being that I can do something like a sidebar where the current user (the logged-in one) can view a list of other people's orders that he can view.
  For example</p>
  
  <p>Three other Users who have some Orders that he can view should be eventually displayed like this:</p>
  
  <ol>
  <li>Jack (2)
  
  <ul>
  <li>Basic Order (registry_id: 1)</li>
  <li>New Order (registry_id: 29)</li>
  </ul></li>
  <li>Amy (4)
  
  <ul>
  <li>Short Order (registry_id: 12)</li>
  </ul></li>
  <li>Jill (5)
  
  <ul>
  <li>Hardware Order (14)</li>
  <li>Pink Order (17)</li>
  <li>Software Order (76)</li>
  </ul></li>
  </ol>
  
  <p>(The number in brackets are the respective user_id or registry_id)</p>
  
  <p>So to find the list of all of the orders that the current user can find (assuming user_id of the current user is 1), would be found by doing</p>
  
  <pre><code>@viewable_orders = Viewable.find(:all, :conditions =&gt; ["user_id=?", 1])
  </code></pre>
  
  <p>And that would give me the collection of the above 6 registries. Now, the easiest way to do this, is for me to just have a list of</p>
  
  <pre><code>+ Jill's Hardware Order
  + Jill's Pink Order
  + Amy's Short Order
  + etc
  </code></pre>
  
  <p>But that gets ugly for long lists. </p>
  
  <p>Thanks!</p>