Yii Framework Forum: Relation with group byfrom other table - Yii Framework Forum

Jump to content

Page 1 of 1
  • You cannot start a new topic
  • You cannot reply to this topic

Relation with group byfrom other table

#1 User is offline   Daniel 

  • Standard Member
  • PipPip
  • Yii
  • Group: Members
  • Posts: 292
  • Joined: 26-September 09

Posted 07 November 2017 - 01:28 AM

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
0

Share this topic:


Page 1 of 1
  • You cannot start a new topic
  • You cannot reply to this topic

1 User(s) are reading this topic
0 members, 1 guests, 0 anonymous users