Answer the question
In order to leave comments, you need to log in
How to filter data by intermediate link table (hasMany/hasOne with via/viaTable) in Yii2 model?
there is a link according to the scheme Buyer - Sales - Supplier, i.e. The Buyer is connected to suppliers through Sales
for the getter in the Buyer model, we have
return $this->hasMany(ПОСТАВЩИКИ::className(), ['ПОСТАВЩИК_ID' => 'ПРОДАЖИ_ID_ПОСТАВЩИКА'])
->viaTable('ПРОДАЖИ', ['ПРОДАЖИ_ID_ПОКУПАТЕЛЯ' => 'ПОКУПАТЕЛЬ_ID'])
Answer the question
In order to leave comments, you need to log in
return $this->hasMany(ПОСТАВЩИКИ::className(), ['ПОСТАВЩИК_ID' => 'ПРОДАЖИ_ID_ПОСТАВЩИКА'])
->viaTable(
'ПРОДАЖИ',
['ПРОДАЖИ_ID_ПОКУПАТЕЛЯ' => 'ПОКУПАТЕЛЬ_ID'],
function ($query) {
$query->andWhere(['СТАТУС_ПРОДАЖИ' => 'АКТИВНА']);
});
return $this->hasMany(ПОСТАВЩИКИ::className(), ['ПОСТАВЩИК_ID' => 'ПРОДАЖИ_ID_ПОСТАВЩИКА'])
->viaTable('ПРОДАЖИ', ['ПРОДАЖИ_ID_ПОКУПАТЕЛЯ' => 'ПОКУПАТЕЛЬ_ID'])->where(['table_name.columns' => value])
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question