title: yii active record join models
body: <p>Using Yii framework.</p>
  
  <p>I have 3 models.</p>
  
  <p>Articles - table articles(id, name) </p>
  
  <p>ArticlesToAuthors - table articles_to_authors (id, article_id, author_id, type)</p>
  
  <p>Authors - table authors (id, name)</p>
  
  <p>I need to get authors.*, article_to_authors.type for specific article_id.</p>
  
  <p>I was trying to make relation in ArticlesToAuthors model like that:</p>
  
  <pre><code>'authors'  =&gt; array(self::HAS_MANY, 'Authors', array('id' =&gt; 'author_id'), ),
  </code></pre>
  
  <p>then i made query:</p>
  
  <pre><code>$authors = ArticlesToAuthors::model()-&gt;with('authors')-&gt;findAll(array('condition' =&gt; 'article_id=2217') );
  
  
  foreach($authors as $a)
  {
       //this is not working
       #var_dump($a-&gt;authors-&gt;name);
           #var_dump($a-&gt;name);
  
       //this works fine
       foreach($a-&gt;authors as $aa)
       {
              var_dump($aa-&gt;name);
       }
  }
  </code></pre>
  
  <ol>
  <li><p>Can i get all active record object in one and not to do foreach in foreach?
  I need an analogue to sql "SELECT atoa.<em>, a.</em> FROM <code>articles_to_authors</code> atoa LEFT JOIN authors a ON atoa.author_id=a.id WHERE atoa.article_id=:article_id"</p></li>
  <li><p>Am i doing right?</p></li>
  </ol>
  
  <p>p.s. - sorry for my bad english.</p>