Answer the question
In order to leave comments, you need to log in
How to access the columns of a joined table?
Hello!
There are a couple of tables in the content and category database. Models have been created for them and connections have been configured.
Both tables have the same fields: id, alias and a few more
In the content model
public function getCategory()
{
return $this->hasOne(Category::class, ['id' => 'category_id']);
}
$content = Content::find()
->select([
Content::tableName() . '.alias',
Content::tableName() . '.title',
(другие нужные поля из таблиц content)
'cat.alias catalias',
(другие нужные поля из таблиц category)
])
->where([$tblContent.'.id' => $id])
->joinWith('category cat')
->one();
Answer the question
In order to leave comments, you need to log in
print_r($content->category); gives nothing
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question