title: Get all associated objects on self join objects and its children
body: <p>I am trying to find all the associated friends with my Person, self-join, record and all its children. </p>
  
  <p>Here is an example I am trying to run. I have a Person record, lets call it <code>@person</code>, that has 4 'children'. </p>
  
  <p>These children all have many friends. </p>
  
  <p>When I query <code>@person</code>, I want all the friends of itself and then the four children below it. </p>
  
  <p>Is there a way to do this without going: <code>friends = @parent.friends + @parent.children.map {|c| c.friends }</code>? </p>
  
  <p>Would really love to do it with one database query. My database is postgresql also.</p>
  
  <p>Here is an example of how my records are set up.</p>
  
  <pre><code>class Person &lt; ActiveRecord::Base
  
    belongs_to :parent, :class_name =&gt; "Person", :foreign_key =&gt; "parent_person_id"
    has_many :children, :class_name =&gt; "Person", :foreign_key =&gt; "parent_person_id"
    has_many :friends
  
  end
  
  class Friend &lt; ActiveRecord::Base
    belongs_to :person
  end
  </code></pre>