Answer the question
In order to leave comments, you need to log in
How to add additional fields to the selection in the pivot table?
There are two models that I link in the following way:
public function getElement()
{
return $this->hasMany(Element::className(), ['id' => 'element_id'])
->viaTable(ElementCategory::tableName(), ['category_id' => 'id']);
}
public function getElement()
{
return $this->hasMany(Element::className(), ['id' => 'element_id'])
->viaTable(ElementCategory::tableName(), ['category_id' => 'id'] ,
function($query){$query->select(['field_1', 'field_2', 'field_3', 'field_4']););
}
Answer the question
In order to leave comments, you need to log in
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question