i have 2 table post and content_translate
table post: id,stt
table content_translate: id,id_join,title,id_lang
code file Post.php in Model
namespace app\models;
use Yii;
class Post extends \yii\db\ActiveRecord
{
public static function tableName()
{
return 'post';
}
public function getContent_translate()
{
return $this->hasMany(Content_translate::className(), ['id_join' => 'id']);
}
}
class Content_translate extends \yii\db\ActiveRecord
{
public function getPost()
{
return $this->hasOne(Post::className(), ['id' => 'id_join']);
}
}
code controller
$test= new Post();
$test=Post::find()
->joinWith('content_translate')
->one();
echo $test->id; //best
how to echo title,id_lang in table content_translate