title: Creating subselect string with ActiveRecord (Rails Tutorial 2nd edition, Listing 11.45)
body: <p>In <a href="http://ruby.railstutorial.org/chapters/following-users#code%3afrom_users_followed_by_final" rel="nofollow">listing 11.45</a> of Chapter 11 of The Rails Tutorial 2nd edition, the <code>from_users_followed_by</code> class method of the <code>Micropost</code> class is defined as follows:</p>
  
  <pre><code>class Micropost &lt; ActiveRecord::Base
  ...
    def self.from_users_followed_by(user)
      followed_user_ids = "SELECT followed_id FROM relationships
                           WHERE follower_id = :user_id"
      where("user_id IN (#{followed_user_ids}) OR user_id = :user_id", 
            user_id: user.id)
    end
  end
  </code></pre>
  
  <p>In <a href="http://ruby.railstutorial.org/chapters/following-users#fn:11.13" rel="nofollow">footnote 13</a> of the chapter, there is a link to <a href="http://pivotallabs.com/users/jsusser/blog/articles/567-hacking-a-subselect-in-activerecord" rel="nofollow">this blog post</a> which says you can use the ActiveRecord internal method <code>construct_finder_sql</code> with the <code>send</code> method if you want to create a subselect string.  So, I attempted to replace the <code>followed_user_ids</code> string with:</p>
  
  <pre><code>followed_user_ids = Relationship.send(:construct_finder_sql,
                                        select: "followed_id",
                                        conditions: { follower_id: :user_id })
  </code></pre>
  
  <p>Only problem is that <code>construct_finder_sql</code> was <a href="http://apidock.com/rails/ActiveRecord/Base/construct_finder_sql/class" rel="nofollow">depreciated</a> in Rails 3, so as well as not knowing if what I wrote was at all correct, I can't use it anyway.  So, is there a Rails 3 way of creating a subselect string using ActiveRecord (that could preferably still use the <code>:user_id</code> parameter) that would work in this situation?</p>