title: Phalcon - How do i do a SELECT IN Subquery with Phalcon models?
body: <p>I need to know how to do i do a subquery type selection with phalcon models? </p>
  
  <p>for example i want to select all the users who viewed me, they are stored in the UserView table with columns 'id','user_from','user_to' (mapped by User table user_id to either user_from or user_to)</p>
  
  <p>so i want to select all the users who has a user_to as with the current user, and group by user_to make sure i only get one recorded, I wrote below function to do this but there is fundamental two problems </p>
  
  <p><strong>1. Is how to do sub-query using phalcon models</strong></p>
  
  <p><strong>2. Is my logic correctly applied on the back-end of the DB (as i cant see real executed query)</strong></p>
  
  <pre><code>public function getUserWithViewedMe($limit=1000000){
          return  User::query()
              -&gt;rightJoin("XYZ\Models\UsersView")
              -&gt;andWhere(" XYZ\Models\UsersView.user_from IN :user_id: ",
                                array('user_id' =&gt; $this-&gt;user-&gt;user_id) )
              -&gt;group('user_id')
              -&gt;order("XYZ\Models\UsersView.id DESC ")
              -&gt;limit($limit)
              -&gt;execute();
      } 
  </code></pre>
  
  <p>This returns empty set... </p>