Dear All,
I need to define relation for this situation,
I have four tables,
Budget => contains information about budget header
BudgetDetail => contains detail works for this budget.
id
budgetFk [FK to budget]
workFk [FK to Work]
quantity
Work => Each work will be done
id
name
unit
unitPrice
categoryFk [FK to category]
Category => Grouping of works
id
name
I want to display sum of (unitPrice in work * quantity in BudgetDetail) group by each work’s category’, the output should be
categoryA 550,000
categoryB 250,000
categoryD 150,000
How can I achieve this?
So far, I can only get until work by doing this,
/**
* @return \yii\db\ActiveQuery
*/
public function getBudgetDetails() {
return $this->hasMany(BudgetDetail::className(), ['budgetFk' => 'id']);
}
/**
* @return \yii\db\ActiveQuery
*/
public function getWorkDetails() {
return $this->hasMany(Work::className(), ['id' => 'workFk'])->via('budgetDetails');
}
TIA,
Daniel