Yii2 activerecord select custom attributes from related table
<p>When I'm trying to select custom attributes from record</p>

<pre><code> $data = Emotion::find()
        -&gt;select('em_id, em_name, tbl_post.post_id, tbl_post.post_header')
        -&gt;where(['em_id' =&gt; $id])
        -&gt;joinWith('posts')
        -&gt;one();
</code></pre>

<p>I've got an answer model, where related field have full set of table fields.
Trace message looks like this:</p>

<pre><code> app\models\Emotion#1
 ( [yii\db\BaseActiveRecord:_attributes] =&gt; 
[ 'em_id' =&gt; 4
'em_name' =&gt; 'test_em']
[yii\db\BaseActiveRecord:_related] =&gt; 
[ 'posts' =&gt; 
[ 0 =&gt; app\models\Post#2 ( [yii\db\BaseActiveRecord:_attributes] =&gt; 
[ 'post_id' =&gt; 10
'post_header' =&gt; 'some header' 
'post_date' =&gt; '2015-06-24 13:40:25', 
'post_descr' =&gt; 'Rocco, continue the joke'
'post_content' =&gt; 'test content'...
</code></pre>

<p>So, maybe i did something wrong or this is a framework issue.</p>

<p>Found a workaround here: <a href="https://github.com/yiisoft/yii2/issues/9495" rel="nofollow">Yii2 GitHub issue</a></p>

<p>Which for my case looks like this:</p>

<pre><code>$data = Emotion::find()
        -&gt;select('em_id, em_name, tbl_post.post_id, tbl_post.post_header')
        -&gt;where(['em_id' =&gt; $id])
        -&gt;joinWith('posts')
        -&gt;createCommand()
        -&gt;queryAll();
</code></pre>

<p>And the output of this request will be an raw array.
Is there an another way to have an ActiveRecord object in a response data?</p>