A
A
Artem2015-02-06 13:51:35
Yii
Artem, 2015-02-06 13:51:35

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']);
  }

in the ElementCategory table, in addition to id-shnikov, there are more fields that need to be added to the selection. How can this be implemented?
Tried like this:
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']););
  }

does not give an error, nor these fields are selected

Answer the question

In order to leave comments, you need to log in

1 answer(s)
M
Maxim Timofeev, 2015-02-08
@webinar

What does debug say?

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question