title: join and where in deep associations
body: <p>i have Projects, which have many Users, and that users have many partners. so associations would look like that:</p>
  
  <p>Project: has_many: users <br>
  User: belongs_to: project, has_many: partners <br>
  Partner: belongs_to: user <br></p>
  
  <p>So now i whant to join those three clases, get data by partner id's and then serialize everything. 
  result should look like this, if i search for partner id= 1,2:</p>
  
  <pre><code>result = {project.id:1, user.id:1, partner.id:1},
  {project.id:1, user.id:1, partner.id:2},
  {project.id:1, user.id:2, partner.id:1},
  {project.id:2, user.id:1, partner.id:1}
  </code></pre>
  
  <p>p.s. result variable doesn't have to have all that joined information, information should be returned through serializer.</p>
  
  <p>so here is how i tried to do that:</p>
  
  <pre><code>projects = Project.joins(:users, :partners).where(partners: { partner_id: ids })
  </code></pre>
  
  <p>after serializer this returns project with user and all partners instead of one that id is equal what i have searched.</p>
  
  <p>Also tried another way, but it won't work at all, i get error:</p>
  
  <pre><code>projects = Project.joins(:users, :partners).where(users: {partners: { partner_id: ids }})
  </code></pre>
  
  <p>In only one association if i need to search by user id it works well :</p>
  
  <pre><code>projects = Project.joins(:users).where(users: { user_id: ids })
  </code></pre>
  
  <p>Any idea how to get all projects with all users and all partners, that partner id is equal to searched one?</p>
  
  <p>Thanks!</p>
  
  <p>UPDATE:</p>
  
  <p>I have tried nested joint, but it doesn't work also :</p>
  
  <pre><code>projects = Project.joins(users: :partner).where(partners: { partner_status_id: ids })
  </code></pre>
  
  <p>here is the result SQL:</p>
  
  <pre><code>SELECT "projects".* FROM "projects" INNER JOIN "users" ON "users"."partner_id" = "projects"."id" INNER JOIN "partners" ON "partners"."user_id" = "users"."id" WHERE "partners"."partner_status_id" = 2
  </code></pre>