title: Rails 2.3: how to handle complex joins without writing custom SQL code
body: <p>I've looked trough the already asked questions but couldn't find an answer.</p>
  
  <p>I've some models: </p>
  
  <p>Each User can cast many Votes, each Vote is linked to one Post, each Post can be linked to many Users.  Each User can cast only one vote per post.</p>
  
  <pre><code>class User &lt; ActiveRecord::Base
    has_many :posts, :through =&gt; :user_posts
    has_many :user_posts
  end
  
  class Vote &lt; ActiveRecord::Base
    belongs_to :user
    belongs_to :post 
  end
  
  class Post &lt; ActiveRecord::Base
    has_many :users, :through =&gt; :user_posts
    has_many :user_posts, :dependent =&gt; :destroy
    has_many :votes, :dependent =&gt; :destroy
  end
  
  class UserPost &lt; ActiveRecord::Base
    belongs_to :user
    belongs_to :post  
  end
  </code></pre>
  
  <p>What I'm trying to accomplish is to count how many times "User A" has voted for posts that belongs to "User B" in the last day.</p>
  
  <p>I can do this with a full SQL query but I'd like to know if there is an easied "Rails-friendly way" to perform this.</p>
  
  <p>Thanks!</p>
  
  <p>Augusto</p>