title: Yii2 relationship hasOne
body: <p>I have 2 simple models:</p>
  
  <pre><code>class Page extends ActiveRecord {
  
      public static function tableName() {
          return 'page';
      }
  
      public function getPageType() {
          return $this-&gt;hasOne(PageType::className(), ['id', 'page_type_id']);
      }
  }
  
  class PageType extends ActiveRecord {
  
      public static function tableName() {
          return 'page_type';
      }
  
      public function getPages() {
          return $this-&gt;hasMany(Page::className(), ['page_type_id', 'id']);
      }
  
  }
  </code></pre>
  
  <p>I am trying to get a list of pages and filter them by <code>page_type_id</code>, so i am doing:</p>
  
  <pre><code>Page::find()
       -&gt;joinWith('pageType')
       -&gt;where(['page.service_id' =&gt; $this-&gt;serviceId, 'page.active' =&gt; 1])
       -&gt;all();
  </code></pre>
  
  <p>But I am getting the following error:</p>
  
  <pre><code>SQLSTATE[42S22]: Column not found: 1054 Unknown column 'page_type.0' in 'on clause'
  The SQL being executed was: SELECT `page`.* FROM `page` 
  LEFT JOIN `page_type` 
     ON 
       `page`.`id` = `page_type`.`0` 
        AND 
       `page`.`page_type_id` = `page_type`.`1` 
  WHERE 
        (`page`.`service_id`=1) AND (`page`.`active`=1)
  </code></pre>
  
  <p>Any ideas?</p>