title: Yii joining two table using relations in model
body: <p>Hi I have these two tables that I want to join using relations in Yii, The problem is Im having a hard time figuring out how Yii relation works.</p>
  
  <pre><code>picturepost
      id
      title
      link_stat_id
  
  linkstat
      id
      link
      post_count
  </code></pre>
  
  <p>I also have a working SQL query. This is the query I want my relation to result when I search when I want to get <strong>picturepost</strong></p>
  
  <pre><code>SELECT picturepost.id, picturepost.title,linkstat.post_count   
  FROM picturepost
  RIGHT JOIN linkstat
  ON picturepost.link_stat_id=linkstat.link;
  </code></pre>
  
  <p>I want something like this when I search for a post.</p>
  
  <pre><code>$post = PicturePost::model() -&gt; findByPk($id);
  echo $post-&gt;linkCount;
  </code></pre>
  
  <p>Here's my table for extra info:</p>
  
  <pre><code>CREATE TABLE IF NOT EXISTS `picturepost` (
      `id` bigint(20) unsigned NOT NULL AUTO_INCREMENT,
      `title` text COLLATE utf8_unicode_ci DEFAULT NULL,
       `link_stat_id` char(64) COLLATE utf8_unicode_ci NOT NULL
  ) ENGINE=MyISAM;
  CREATE TABLE IF NOT EXISTS `linkstat` (
    `id` bigint(20) NOT NULL AUTO_INCREMENT,
    `link` char(64) COLLATE utf8_unicode_ci NOT NULL,
    `post_count` int(11) DEFAULT '0',
    PRIMARY KEY (`id`),
    KEY `post_count` (`post_count`),
    KEY `link_stat_id` (`link`)
  ) ENGINE=InnoDB;
  </code></pre>
  
  <p>Thanks in advance I hope I explained it clearly.</p>