How to operate the aggregation query of the association model in thinkphp5, please give an example.
phpcn_u16587
phpcn_u16587 2017-08-20 10:13:32
0
1
1301

There are two tables: bill (bill) and detail (bill details)

bill fields: billid (bill ID), billdate (billing date), total (total amount)...

detail fields: detailid (detail ID), billid (bill ID), amount (amount), incometype (income category)...

Build two models:

class Bill extends Model {

//Associated to the bill detail table

public function detail(){

return $this->hasMany('Detail', ' billid');

}

}

class Detail extends Model{

//Associated to the bill table

public function bill(){

return $this->belongsTo('Bill', 'billid');

}

}

Q: If you want to use the model object to calculate the income amount according to the income category in the bill details, how should you write it?

phpcn_u16587
phpcn_u16587

Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!